import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Scanner;
public class StringTest {
public static void main(String[] args) {
ArrayList<String> list = new ArrayList<String>();
System.out.println("开始输入,以end结束:");
while (true) {
Scanner sc = new Scanner(System.in);
String line = sc.nextLine();
if ("end".equals(line)) {
System.out.println("end!结束!");
break;
}
list.add(line);
}
Collections.sort(list, new myComparator_StringTest());
System.out.println(list);
}
}
class myComparator_StringTest implements Comparator<String> {
@Override
public int compare(String s1, String s2) {
int num = s2.compareTo(s1);
return num;
}
} |