你说的排序是什么意思?是按字符串长度吗?
要是按长度排序我有。
public class SortUtil
{
    public SortUtil()
    {
    }    protected static void swap2( String[] x, int a, int b )
    {
        String t = x[ a ];
        x[ a ] = x[ b ];
        x[ b ] = t;
    }    protected static void sortArrys( String[] a )
    {
        String temp;        for ( int i = 0; i < ( a.length / 2 ); i++ )
        {
            temp = a[ a.length - i - 1 ];
            a[ a.length - i - 1 ] = a[ i ];
            a[ i ] = temp;
        }        return;
    }
    
    /**
     * 对string数组按其中string长度由长到短排序
     * @param String[]
     */
    public static void sortByStrLength( String[] s )
    {
        // Insertion sort on smallest arrays
        int[] is = new int[ s.length ];
        int off = 0;
        int len = is.length;        for ( int i = 0; i < is.length; i++ )
        {
            is[ i ] = s[ i ].getBytes().length;
        }        if ( true )
        {
            for ( int i = off; i < len + off; i++ )
            {
                for ( int j = i; j > off && is[ j - 1 ] > is[ j ]; j-- )
                {
                    swap2( s, j, j - 1 );                    for ( int h = 0; h < is.length; h++ )
                    {
                        is[ h ] = s[ h ].getBytes().length;
                    }
                }
            }            sortArrys( s );            return;
        }
    }    public static void main( String[] args )
    {
        String[] s = {
            "中", "bbbb", "cc", "d", "eeeee", "ff", "asdfda", "eef", "de", 
            "cc中国", "中国人", "卧室中国"
        };
        sortByStrLength( s );        for ( int k = 0; k < s.length; k++ )
        {
            System.out.println( s[ k ] );
        }
    }
}

解决方案 »

  1.   

    不是按照长度。是按照汉语拼音
    如上面的例子,
    结果要为北京------(beijing)
    亚运会-----(yayunhui)
    中国--------(zhongguo)
      

  2.   

    我这个排序是按照GB2312的顺序进行排列,基本上会按照拼音排序的
    我没有做优化,重复次数较多。你可以改进改进。
    public class Test {
    public static class PYComparator implements Comparator{
    public int compare(Object o1,Object o2) {
    try {
    byte[] buf1 = ((String)o1).getBytes("GB2312");
    byte[] buf2 = ((String)o2).getBytes("GB2312");
    int size = Math.min(buf1.length,buf2.length);
    for(int i = 0; i < size; i++) {
    if(buf1[i] < buf2[i])
    return -1;
    else if(buf1[i] > buf2[i])
    return 1;
    }
    return buf1.length - buf2.length;
    }
    catch (UnsupportedEncodingException ex) {
    return 0;
    }
    }
    }
    public static void main(String[] args) throws Exception{
    String[] str = {"北京","中国","亚运会"};
    Arrays.sort(str,new PYComparator());
    for(int i = 0 ; i < str.length; i++)
    System.out.println(str[i]);
    }
    }
      

  3.   

    楼上的大哥。
    我是java初学,谢谢了。
    结帖给分。呵呵