题解 | #字符串排序#
字符串排序
http://www.nowcoder.com/practice/5af18ba2eb45443aa91a11e848aa6723
直接利用java的数组Arrays.sort方法
import java.util.*; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); Collection<String> list = new ArrayList<String>(); while(in.hasNextLine()){ int n = Integer.parseInt(in.nextLine()); for(int i=0;i<n;i++){ String line = in.nextLine(); list.add(line); } } Object[] array = list.toArray(); Arrays.sort(array); for(Object str:array){ System.out.println(str.toString()); } } }