Java排序

阅读更多
public int compare(String s1, String s2) {
        return ((java.text.RuleBasedCollator)java.text.Collator.
            getInstance(java.util.Locale.CHINA)).compare(s1, s2);
    }

这样就可以对中文排序了 还算好用 还在网上看到一个别人的排序
import java.util.*;
import java.text.*;

public class SortPinyin {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Comparator cmp = Collator.getInstance(java.util.Locale.CHINA);
        String[] arr = { "张三","张A", "李四", "王五", "赵六", "F-16", "12345", "^%$%"};
        Arrays.sort(arr, cmp);
        for (int i = 0; i < arr.length; i++)
            System.out.println(arr[i]);
        System.out.println();
    }

}

你可能感兴趣的:(Java,F#)