有时候,可能需要获取a~z、A~Z组成的26个字母的字符串,这篇文章介绍一种简单的方法。
只需要几句简单到不能再简单的代码!你不会还在傻傻地一个个字母敲吧~
/**
 * @author heyunlin
 * @version 1.0
 */
public class Example {
    /**
     * 小写字母
     */
    private static final StringBuilder LOWER_LETTERS;
    /**
     * 大写字母
     */
    private static final StringBuilder UPPER_LETTERS;
    static {
        LOWER_LETTERS = new StringBuilder();
        UPPER_LETTERS = new StringBuilder();
        for (int i = 97; i < 122; i++) {
            char letter = (char) i;
            LOWER_LETTERS.append(letter);
        }
        for (int j = 65; j < 91; j++) {
            char letter = (char) j;
            UPPER_LETTERS.append(letter);
        }
    }
    public static void main(String[] args) {
        System.out.println(LOWER_LETTERS);
        System.out.println(UPPER_LETTERS);
    }
} 
程序运行结果




















