我们需要从字符串中获取大写字符流。有两种方法:
word.toUpperCase().chars()
word.chars().map(Character::toUpperCase)
哪种方法更好?
P.S. 根据评论要求,我在此指定了使用代码的整个方法:
private int[] toSortedChars(final String word) {
return word.chars().map(Character::toLowerCase).sorted().toArray();
}
该方法用于解决练习: https://exercism.org/tracks/java/exercises/anagram。
IntStream
,您可以澄清一下这一点吗? - Lino