只需添加一个比较器类,然后在TreeSet中使用它,如下所示:
class Comparatorbuff implements Comparator<StringBuffer> { @Override public int compare(StringBuffer s1, StringBuffer s2) { return s1.toString().compareTo(s2.toString()); }}in your main method: modify as followsSet<StringBuffer> sb=new TreeSet<StringBuffer>(new Comparatorbuff());
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)