码迷,mamicode.com
首页 > 编程语言 > 详细

一个对含中文字符串在内的字符串排序简便方法

时间:2017-06-29 22:14:17      阅读:181      评论:0      收藏:0      [点我收藏+]

标签:字符串   排序   

public class StringSort {
	public static void main(String[] args){
		String[] arr = {"1101", "1100", "1001", "1110","1100","1101","0010","1000","0101","0011","1110","1011","0111","0110","1000","0100","1010",
				"aabb","aabc","abab","baba","acbc","baca","bcab","cacb","cbba","你","我","他","你好","我好","他好","她好"};
		
		Comparator<Object> cmp = Collator.getInstance(java.util.Locale.CHINA);
		Collections.sort(Arrays.asList(arr),Collections.reverseOrder(cmp));

		//想应用拼音排序只能用reverseOrder方法,不过如果需要正排可以对数组反向读取
		for(int i=0;i<arr.length;i++){
			System.out.println(arr[i]);
		}
	}
}

中文字符串是按拼音排序的

本文出自 “空空如也” 博客,谢绝转载!

一个对含中文字符串在内的字符串排序简便方法

标签:字符串   排序   

原文地址:http://6738767.blog.51cto.com/6728767/1943229

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!