如何对几个字符串进行字典排序
发布网友
发布时间:2022-07-19 16:56
我来回答
共1个回答
热心网友
时间:2023-10-16 19:58
//按照中文第一个字母升序排列的实现
import java.text.Collator;
import java.util.Arrays;
import java.util.Comparator;
public class test {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Comparator<Object> com=Collator.getInstance(java.util.Locale.CHINA);
String[] newArray={"上海","天津","广州","杭州","辽宁","南京","武汉","北京","厦门","内蒙"};
Arrays.sort(newArray,com);
for(String i:newArray){
System.out.print(i+" ");
}
}
}