To achieve sorting, there are generally two ways, here is not applicable to basic types, and basic types typically have static methods in Arrays.
1. The object itself implements the Comparable interface, then the instance of such classes can be sorted. About Comparable: http://blog.9cbs.net/treeroot/archive/2004/09/09/99613.aspx As long as the Compailable interface, You can call the Elections of Collectes to sort the elements in the collection.
2. Specify a COMPARATOR, which is an instance of the class class. But Java itself only provides a COMPARATOR implementation, which is Collectes.ReverseOrder (). The method returns an ink sequence that has already implemented the Comparable interface.
Look at the full content of Comparator:
Public interface comparator {Int Compare (Object O1, Object O2); Boolean Equals (Object Obj); Equals method using Object. Acparactor is generally as an anonymous class, and you need to specify a Compare when you don't implement a collection of Comparable objects.
Here is an example of the simple IntegerList List = new arraylist (); list (new integer (53)); list.add (new integer (53)); list.add (NEW) Integer (34)); Collects.Sort (List);
For Comparable, we use Object, follow the Hashcode size. List list = new arraylist (); list.add (new object (new object (new object ()); list.add (New) Object ()); collections.sort (list, new compare () {public int compare (Object O1, Object O2) {return (O1.hashcode () - O2.hashcode ();})