Better way to generate array of all letters in the alphabet

后端 未结 17 2010
说谎
说谎 2020-12-02 10:56

Right now I\'m doing

for (char c = \'a\'; c <= \'z\'; c++) {
    alphabet[c - \'a\'] = c;
}

but is there a better way to do it? Similar

17条回答
  •  借酒劲吻你
    2020-12-02 11:32

    Finally you are getting a char array with alphabet. Why did you do so hard way using a loop ?

    It is just

    char[] alphabet=new char[]{'a','b',.........,'z'}
    

提交回复
热议问题