题解 | #字符串排序#
字符串排序
https://www.nowcoder.com/practice/5af18ba2eb45443aa91a11e848aa6723
import java.util.Scanner; import java.util.ArrayList; import java.util.Arrays; import java.util.Scanner; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Scanner; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); String line = in.nextLine(); // 获取多少行 int l = Integer.parseInt(line); ArrayList<String> list = new ArrayList<>(); // 循环多少次 while (l >= 1) { String line1 = in.nextLine(); boolean add = list.add(line1); l--; } Collections.sort(list); for (int i = 0; i < list.size(); i++) { System.out.println(list.get(i)); } } }