1 package demo; 2 3 import java.text.Collator; 4 import java.util.ArrayList; 5 import java.util.Arrays; 6 import java.util.Comparator; 7 8 public class Demo { 9 10 @SuppressWarnings("unchecked") 11 public static void main(String[] args) { 12 13 sort(); 14 } 15 16 //按照中文第一个字母升序排列的排序 17 public static void sort(){ 18 Comparator<Object> com=Collator.getInstance(java.util.Locale.CHINA); 19 String[] newArray={"中山","汕头","广州","安庆","阳江","南京","武汉","北京","安阳","北方"}; 20 Arrays.sort(newArray,com); 21 for(String i:newArray){ 22 System.out.print(i+" "); 23 } 24 } 25 26 }
时间: 2024-10-02 01:55:05