总结:
package com.ja; import java.util.Arrays; import java.util.Collections; public class mili { public static void main(String[] args) { int a[] = new int[] { 3, 25, 231, 1, 21, 4, 12 }; Arrays.sort(a); for (int i = 0; i < a.length; i++) { System.out.print(a[i] + " "); } String b[] = new String[] { "daf", "A", "rRT", "TE", "erE" }; Arrays.sort(b); for (int i = 0; i < b.length; i++) { System.out.print(b[i] + " ");// 字符串排序先大写后小写 } String c[] = new String[] { "WTR", "cTW", "at", "Edf", "Xt", "id", "us" }; Arrays.sort(c, String.CASE_INSENSITIVE_ORDER);// 字符串忽略大小写,排序 for (int i = 0; i < c.length; i++) { System.out.print(c[i] + " "); } String w[] = new String[] { "Ex", "wew", "ADE", "ade", "Sdf" }; Arrays.sort(w, Collections.reverseOrder());// 反向排序,使用对象类型,c即为对象名 for (int i = 0; i < w.length; i++) { System.out.print(w[i] + " "); } String d[] = new String[] { "fwq", "Adf", "ewa", "DQA" }; Arrays.sort(d, String.CASE_INSENSITIVE_ORDER);// 忽略大小写的反向排序 Collections.reverse(Arrays.asList(d)); for (int i = 0; i < d.length; i++) { System.out.print(d[i] + " "); } } }