- import java.util.*;
- public class SetDemo {
- public static void main(String[] args) {
- shunxu();
- }
- private static void shunxu() {
- // TODO Auto-generated method stub
- Cmp cmp = new Cmp();
- Set ts = new TreeSet(cmp);
- ts.add("zhangsan");
- ts.add("lisi");
- ts.add("wangwu");
- ts.add("zhouliu");
- ts.add("zhaoqi");
- ts.add("sunba");
-
- for(Object s:ts)
- System.out.println(s);
-
- }
-
- }
- class Cmp implements Comparator{
-
- @Override
- public int compare(Object o1, Object o2) {
- // TODO Auto-generated method stub
- return 1;
- }
- }
复制代码 |