S
Shawn
Hi,
I was reading the following part from a tutorial. I cannot understand
it. Could you kindly help me understand it? I know the intention is to
provide your own comparator so that your list can be sorted by using it.
I am not clear how to apply the object of Comparator to the list. Can
you fill in a little more code to show me how it works?
Thank you very much.
======================copied from a tutorial======================
This example demonstrates an anonymous class definition for a comparator
that is passed to the sort() method in the Collections class. Assume
that aList is a valid List of data that is to be sorted.
Collections.sort (aList,
new Comparator() { // implements the IF
public int compare (Object o1, Object o2 ) throws ..{
.... implementation for compare()
} // end of compare()
} // end of Comparator implementation
); // closed paren for sort() and end of statement semicolon
I was reading the following part from a tutorial. I cannot understand
it. Could you kindly help me understand it? I know the intention is to
provide your own comparator so that your list can be sorted by using it.
I am not clear how to apply the object of Comparator to the list. Can
you fill in a little more code to show me how it works?
Thank you very much.
======================copied from a tutorial======================
This example demonstrates an anonymous class definition for a comparator
that is passed to the sort() method in the Collections class. Assume
that aList is a valid List of data that is to be sorted.
Collections.sort (aList,
new Comparator() { // implements the IF
public int compare (Object o1, Object o2 ) throws ..{
.... implementation for compare()
} // end of compare()
} // end of Comparator implementation
); // closed paren for sort() and end of statement semicolon