java中将一个字符串数组按字典序重新排列。高手帮忙解决一下,谢谢!

2024-11-05 03:04:57
推荐回答(2个)
回答1:

import java.util.Arrays;
public class Test{
public static void mian(String[] args){
String sr[] = {"爪哇","汇编","计算机","键盘","鼠标"};
Arrays.sort(sr);
for(int i=0;i System.out.println(sr[i]);
}
}
}
楼主是这个吧?
引入:import java.util.Arrays;
方法:Arrays.sort(数组名);
可以实现对数组按字典顺序排序.....

回答2:

大小写怎么考虑排序?
import java.util.Arrays;

public class Test {

public static void main(String[] args) {

String[] ary = {"test", "abc", "apple", "PEar"};

System.out.println("Before sorted, the array is: " + Arrays.toString(ary));

Arrays.sort(ary);

System.out.println("After sorted, the new array is: " + Arrays.toString(ary));

}

}