|
|
|
|
![]() ![]() |
Apr 9 2008, 02:17 PM
Post
#21
|
|
|
Member [ Level 1 ] Group: [HOSTED] Posts: 47 Joined: 4-February 08 Member No.: 28,119 |
He can always implement Comparator interface to do virtually ANYTHING he want. So I wonder why he wants to reinvent the wheels... after all, libraries are tools which makes you NOT to redo what was already done. I think it is the best solution, provided by Java API - we can simply put desirable business logic of sorting into the method "Comparator::compare()". I do not any reasons to invent anything else. For example: import java.util.Comparator; public class MyItem implements Comparator { ....... public int compare(Object o1, Object o2) { // your business logic of sorting } public boolean equals(Object obj) { // see Sun comments here } } So, we can put objects of MyItem class into appropriated collections (for example, any implementation of SortedSet interface: TreeSet etc.) |
|
|
|
![]() ![]() |
Similar Topics
|
Lo-Fi Version | Time is now: 22nd August 2008 - 01:50 AM |