java--TreeSet比较器排序

package com.test;
import com.bean.Student;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Random;
import java.util.Scanner;
import java.util.TreeSet;

import com.bean.Student;
public class qiantao_1 {

public static void main(String[] args) {
//	extracted_7();
	TreeSet<String> ts= new TreeSet<>(new CompareByLen());
	
	ts.add("aaaaaa");
	ts.add("b");
	ts.add("crr");
	ts.add("wc");
	System.out.println(ts);
}

public int compare(String arg0, String arg1) {
// TODO Auto-generated method stub
int num = arg0.length()-arg1.length();
return num ==0?arg1.compareTo(arg0):num;
}
}

posted @ 2020-06-03 10:22  雨曼晴川  阅读(190)  评论(0编辑  收藏  举报