题解 | #字符串排序#
字符串排序
http://www.nowcoder.com/practice/5190a1db6f4f4ddb92fd9c365c944584
import java.util.*;
public class Main {
static Scanner in = new Scanner(System.in);
public static void main(String[] args) {
String str = in.nextLine();
ArrayList<Character> list = new ArrayList<>();
for (char c: str.toCharArray()) {
if (Character.isLetter(c))
list.add(c);
}
list.sort((a, b)->Character.toLowerCase(a) - Character.toLowerCase(b));
int idx = 0;
for (char c : str.toCharArray()) {
if (Character.isLetter(c)) {
System.out.print(list.get(idx ++ ));
} else {
System.out.print(c);
}
}
}
}