题解 | #字符串排序#
字符串排序
https://www.nowcoder.com/practice/5190a1db6f4f4ddb92fd9c365c944584
import java.util.*; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); char[] chr = in.nextLine().toCharArray(); List<String> list = new ArrayList<String>(); for (char index : chr) { if (Character.isLetter(index)) { list.add(String.valueOf(index)); } } Collections.sort(list, String.CASE_INSENSITIVE_ORDER); Iterator<String> it = list.iterator(); for (char index : chr) { if (Character.isLetter(index)) { System.out.print(it.next()); } else { System.out.print(index); } } } }