package com.heima.test;
import java.util.Comparator;
import java.util.Scanner;
import java.util.TreeSet;
public class Test8 {
/**
*
*/
public static void main(String[] args) {
TreeSet<String> ts = new TreeSet<String>(new Comparator<String>() {
@Override
public int compare(String s1, String s2) {
int num = s2.compareTo(s1);
return num == 0 ? 1 : num;
}
});
Scanner sc = new Scanner(System.in);
System.out.println("请输入字符串,以end结束:");
while (true) {
String s = sc.nextLine();
if (s.equals("end")) {
break;
}
ts.add(s);
}
for (String string : ts) {
System.out.println(string);
}
}
}
|