Java怎么按照汉字字典顺序给字符串排序?
展开全部
//按照中文第一个字母升序排列的实现
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+" ");
}
}
}
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+" ");
}
}
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询