import java.util.Collections;
import java.util.List;
public class StringSort {
public static void main(String[] args) {
String demos[]={"hello","chenhj","test","中国"};
Arrays.sort(demos, new StringComparator());
for(String str:demos){
System.out.println(str);
}
/*Arrays.sort(demos);
for(String str:demos){
System.out.println(str);
}*/
Collections.sort(Arrays.asList(demos));
for(int i=0;i<demos.length;i++){
System.out.println(demos[i]);
}
}
}
---------------------------------------------------------------------------------------
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
public class StringComparator implements Comparator<String>{
public static void main(String[] args) {
}
@Override
public int compare(String o1, String o2) {
// TODO Auto-generated method stub
return o1.compareTo(o2);
}
}