// Relationship between the two: 1. The internal implementation of coollections. sort is implemented using arrays. sort.
// 2. If the objects in the list to be sorted have implemented the comparable interface, you can use arrays. Sort To sort objects.
// 3. If the objects in the list to be sorted do not implement the comparable interface, use collections. sort to sort the objects and implement an instance of the comparator interface by yourself. Collections. Sort has two refactoring methods.
Import java. Text. collator;
Import java. util. arraylist;
Import java. util. arrays;
Import java. util. collections;
Import java. util. comparator;
Import java. util. List;
Import java. util. locale;
Public class testlocale {
/**
* @ Param ARGs
*/
Public static void main (string [] ARGs ){
List sourcelist = new arraylist ();
Sourcelist. Add ("medium ");
Sourcelist. Add ("Hua ");
Sourcelist. Add ("person ");
Sourcelist. Add ("Citizen ");
Sourcelist. Add ("Total ");
Sourcelist. Add ("and ");
Sourcelist. Add ("country ");
Sourcelist. Add ("stupid ");
// 1. Print the Array
System. Out. println ("first print -------------------");
For (INT I = 0; I <sourcelist. Size (); I ++ ){
System. Out. println (sourcelist. Get (I ));
}
// 2. Sort arrays and print the Array
System. Out. println ("second print -------------------");
Object [] sstrings = sourcelist. toarray ();
Arrays. Sort (sstrings );
For (INT I = 0; I <sstrings. length; I ++ ){
System. Out. println (sstrings [I]);
}
// 3. Sort collections
Sourcelist. Clear ();
Sourcelist. Add ("medium ");
Sourcelist. Add ("Hua ");
Sourcelist. Add ("person ");
Sourcelist. Add ("Citizen ");
Sourcelist. Add ("Total ");
Sourcelist. Add ("and ");
Sourcelist. Add ("country ");
Sourcelist. Add ("stupid ");
Collections. Sort (sourcelist, new comparator (){
Public int compare (object _ O1, object _ O2 ){
Return chinesecompare (_ O1, _ O2 );
}
});
System. Out. println ("the third print -------------------");
For (INT I = 0; I <sourcelist. Size (); I ++ ){
System. Out. println (sourcelist. Get (I ));
}
}
Private Static int chinesecompare (object _ ochinese1, object _ ochinese2 ){
Return collator. getinstance (locale. Chinese). Compare (_ ochinese1,
_ Ochinese2 );
}
}