题解 | #字符串排序#
字符串排序
http://www.nowcoder.com/practice/5190a1db6f4f4ddb92fd9c365c944584
Character 排序 array.sort(Comparator.compareInt(Character::toLowerCase));
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner scan = new Scanner(System.in);
while(scan.hasNext()){
String str = scan.nextLine();
List<Character> list = new ArrayList<>();
StringBuilder strb = new StringBuilder();
for(char c : str.toCharArray()){
if(Character.isLetter(c)){
list.add(c);
}
}
list.sort(Comparator.comparingInt(Character::toLowerCase));
for(int i = 0, j = 0; i<str.length(); i++){
if(Character.isLetter(str.charAt(i))){
strb.append(list.get(j));
j++;
}
else{
strb.append(str.charAt(i));
}
}
System.out.println(strb.toString());
}
scan.close();
}
}