首页 > 代码库 > 一个对含中文字符串在内的字符串排序简便方法

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

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]);
		}
	}
}

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

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

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