compare方法是在Comparator接口里定义的:public int compare(Object o1,Object o2)Compares its two arguments for order. Returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.
解决方案 »
- java如何自己写事务(与数据库无关)
- 《Thinking in Java》里的“static Test monitor = new Test()”
- 公式解析器包
- "Exception in thread "main" java.lang.NoSuchMethodError: main"是什么错误?
- 求教:一个正则表达式的写法
- 请问怎么将一个字符串转换成Date类型?
- 请问Java能干什么,java vm的速度是在是太慢!
- 这样的代码也有错!!!
- com.ibm.util.base64 是再那個包里面﹖
- 请问在cmp中怎样设置多表?表与表之间用什么分隔?
- 一个关于notify()的问题
- 高手指教:请问如何定时执行一个任务?
a == b 返回 0
a > b返回 正数
这样在比较的类中就可以调用外部的比较函数确定位置TreeSet的参数应该作用是在你每次插入add("d");时找到一个合适的位置使得它们可以
之后的顺序保持正确
TreeSet ts=new TreeSet(new MyComp());传入的参数new MyComp()是排序是得比较函数。
有public TreeSet(Comparator c)
但是说明中提到Constructs a new, empty set, sorted according to the specified comparator. All elements inserted into the set must be mutually comparable by the specified comparator
参看原贴中应用了Comparator接口的类MyCom
它的方法compare返回的int怎么能使TreeSet的构造函数Constructs a new, empty set, sorted according to the specified comparator?
我就是搞不懂这一点