字符串排序,字符串排序求助!编程高手进!

字符串排序求助!编程高手进! - 故障解答 - 电脑教程网

字符串排序求助!编程高手进!

日期:2006-04-27   荐:
字符串排序求助!编程高手进!问题是:给定字符串数组,按每个字符串首字母排序,顺序为abcd....z(A到Z)例如public void alphabetSort(String str[]){....}请高人帮忙解决一下!本人送分100!给你点提示:比较 它们的ASCII码 就OK了..就象是 比较它们ASCII码的大小 就可以了..public static void alphaSort(String str[]) { TreeSet ts = new TreeSet(); for (int i = 0; i < str.length; i) { ts.add(str[i]); } int i = 0; Iterator it = ts.iterator(); while (it.hasNext()) { str[i ] = (String) it.next(); } }试一下String[] strs={"abc","ade","ed","grgefet"};java.util.Arrays.sort(strs);for(int i=0;i<strs.length;i )System.out.println(strs[i]);}
标签: