- 浏览: 77058 次
文章分类
- 全部博客 (89)
- web service (9)
- subversion (1)
- JBOSS (3)
- interview (23)
- jQery (2)
- ExtJs (0)
- Axis (0)
- Design pattern (3)
- Agile (2)
- mutithread (0)
- Core Java (24)
- programming methods (1)
- SSH (7)
- jee design (1)
- OO (4)
- books (8)
- other (1)
- JSF (7)
- seam (2)
- Weblogic (4)
- JPA (1)
- ADF (1)
- Spring (5)
- Tomcat (1)
- DWR (2)
- JEE (3)
- Servlet (1)
- EJB (1)
- JDBC (3)
最新评论
-
iloveflower:
呵呵。好好学习。。。。。。。。。。。。
java 读书 -
Eric.Yan:
看了一点,不过是电子版的……你这一说到提醒我了,还要继续学习哈 ...
java 读书
I have a list of objects I need to sort on a field, say Score. Without giving much thought I wrote a new class that implements Comparator, that does the task and it works. Now looking back at this, I am wondering if I should have instead have the my class implement Comparable instead of creating a new class that implements Comparator. The score is the only field that the objects will be ordered on. 1. What I have done acceptable as a practice? 2. Is the right approach "First have the class implement Comparable (for the natural ordering) and if an alternative field comparison is required, then create a new class that implements Comparator" ? 3. If (2) above is true, then does it mean that one should implement Comparator only after they have the class implement Comparable? (Assuming I own the original class). Thanks! Use Comparable if you want to define a default (natural) ordering behaviour of the object in question, a common practice is to use a technical or natural (database?) identifier of the object for this. Use Comparator if you want to define an external controllable ordering behaviour, this can override the default ordering behaviour. I would say that an object should implement Comparable if that is the clear natural way to sort the class, and anyone would need to sort the class would generally want to do it that way. If, however, the sorting was an unusual use of the class, or the sorting only makes sense for a specific use case, then a Comparator is a better option. Put another way, given the class name, is it clear how a comparable would sort, or do you have to resort to reading the javadoc? If it is the latter, odds are every future sorting use case would require a comparator, at which point the implementation of comparable may slow down users of the class, not speed them up.
发表评论
-
Java Collection summary
2012-06-16 02:40 536Collection:List、Set Map: ... -
Arrays.fill with multidimensional array in Java
2012-06-15 00:09 655How can I fill a multidimension ... -
Immutable objects
2012-06-14 23:49 668Immutable objects are simply ... -
Implementing hashCode; Transaction.java
2012-06-14 23:43 788Below is the syntax highlight ... -
Lazy initialization
2012-06-14 22:48 768http://www.javapractices.com/to ... -
How to sort an array,mid of linkedlist, reverse int
2012-06-13 07:47 893A common mistake for a beginner ... -
Java各类型转换
2012-06-13 05:25 667各种数字类型转换成字符串型: String s = Str ... -
regular expression
2012-06-13 03:08 4791、Java对反斜线处理的 ... -
string functions
2012-06-13 00:09 795import java.util.*; public c ... -
String array to arraylist
2012-06-13 00:07 545There are some important thing ... -
core java interview summary
2012-06-12 04:11 351http://blog.sina.com.cn/s/blog_ ... -
programming with String
2012-06-12 01:43 527Question: 1) Write code to che ... -
OO Design books -good website
2012-06-07 03:13 660I’m always on the search on goo ... -
Write a String Reverser (and use Recursion!)
2012-06-07 03:03 494Java Interview questions: Write ... -
Java高手必会的要点
2012-05-29 03:28 582http://developer.51cto.com/art/ ... -
How to use getClass().getClassLoader().getResource()
2012-05-29 03:13 1714This is the simplest wat to get ... -
How to override equals method in Java
2012-05-12 02:57 1513Object class holds some very in ... -
Top 30 Programming interview questions
2012-05-12 02:48 877Programming questions are integ ... -
10 example of using ArrayList in Java >>> Java ArrayList Tutorial
2012-05-12 02:37 814ArrayList in Java is most frequ ... -
How to use Comparator and Comparable in Java? With example
2012-05-12 02:21 741Read more: http://javarevisited ...
相关推荐
Comparable&Comparator区别,看完就明白了
详细的介绍了Java中Comparable与Comparator的区别
本文,先介绍Comparable 和Comparator两个接口,以及它们的差异;接着,通过示例,对它们的使用方法进行说明
Java中Comparable和Comparator的区别共3页.pdf.zip
Comparable与Comparator的区别Java开发Java经验技巧共3页.pdf.zip
NULL 博文链接:https://hellogava.iteye.com/blog/1570101
通过简单的例子初步了解Comparable和Comparator的使用,注释很详细
java排序Comparator和Comparable
主要介绍了java 中Comparable与Comparator详解与比较的相关资料,需要的朋友可以参考下
主要介绍了详解Java中Comparable和Comparator接口的区别的相关资料,希望通过本文大家能彻底掌握这部分内容,需要的朋友可以参考下
主要介绍了Java Comparable和Comparator对比详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
要注意的是List,Set,Queue继承了Collection接口,...这里想用一个简单的例子展示一下他们的使用,内容包括:List、Map、Set、Queue,Collections、Comparable与Comparator,排序、搜索,内部类,泛型、重写equals、hashCode
用Comparator 的好处是不需要修改源代码, 而是另外实现一个比较器, 当某个自定义的对象需要作比较的时候,把比较器和对象一起传递过去就可以比大小了, 并
NULL 博文链接:https://gghaomm.iteye.com/blog/1753970
教你学会Comparator和Comparable
comparator接口与Comparable接口的区别
NULL 博文链接:https://chaoyi.iteye.com/blog/2082723
Java-中的-Comparator-和-Comparable.md
主要针对Java中Comparable和Comparator对象进行比较,感兴趣的小伙伴们可以参考一下