well it kind of data structure i need to have in my application so i bent to that . can i get some kind of example how to set up comparator for this scenario ? link or tutorial thanks
Have you read the Comparator interface in the API? Work out a way to get it to return 0 if the two objects are "equal" negative number if less and positive number if more. Also implement the "equals" method of Comparator. Then you pass the Comparator object to the sort() method as a parameter.
a TupleList is not a List<Tuple> and can't be made one even with a cast. Internally a TupleList contains a reference to a List<Tuple>, but this is irrelevant. Either you can make your TupleList class implement List<Tuple> or you can sort the internal List<Tuple> by some other means.
On another note, since you are using generics in the rest of your project, you could eliminate the casts in your Comp.compare() method and make it typesafe by changing it to:
[ March 16, 2007: Message edited by: Garrett Rowe ]
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
Originally posted by Campbell Ritchie: Have you read the Comparator interface in the API? Work out a way to get it to return 0 if the two objects are "equal" negative number if less and positive number if more. Also implement the "equals" method of Comparator...
Why would it be helpful to override the equals() method here? Normally Comparators that I've used have no state.
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
I thought there was an equals method in Comparator...
There is but according to the documentation:
Note that it is always safe not to override Object.equals(Object). However, overriding this method may, in some cases, improve performance by allowing programs to determine that two distinct Comparators impose the same order.
I've just never written one where this would be useful.
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter