更好的方法来生成字母表中所有字母的数组 [英] Better way to generate array of all letters in the alphabet
本文介绍了更好的方法来生成字母表中所有字母的数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
现在我正在做
for (char c = 'a'; c <= 'z'; c++) {
alphabet[c - 'a'] = c;
}
但还有更好的方法吗?类似于Scala的'a'到'z'
but is there a better way to do it? Similar to Scala's 'a' to 'z'
推荐答案
我认为这最终会变得更清洁,你不必处理减法和索引:
I think that this ends up a little cleaner, you don't have to deal with the subtraction and indexing:
char[] alphabet = "abcdefghijklmnopqrstuvwxyz".toCharArray();
这篇关于更好的方法来生成字母表中所有字母的数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文