【发布时间】:2023-03-18 23:15:01
【问题描述】:
如何使用取自另一个字符串的字母顺序创建一个字符串?
假设我有这样的东西
String theWord = "Hello";
如何计算新字符串以使其看起来像“
ehllo
这是单词,但按字母顺序逐个字符排序。
我想出了这个,但我不确定为什么它不起作用,它只是打印出“Hello”
char[] chars = theWord.toCharArray();
Arrays.sort(chars);
String newWord = new String(chars);
System.out.println(newWord);
【问题讨论】:
-
因为大写字母在小写字母之前。
-
你为什么要责怪Java? Java 有很好的文档记录,它会告诉你它在做什么。 The first rule of programming.
标签: java