方法sort(obj [] a)在Java中做什么?
java.util.Arrays类的sort(Object[])方法根据其元素的自然顺序将指定的Object数组按升序排序。
示例
import java.util.Arrays; public class ArrayDemo { public static void main(String[] args) { Object ob[] = {27, 11, 44}; for (Object number : ob) { System.out.println("Number = " + number); } Arrays.sort(ob); System.out.println("排序的对象数组是:"); for (Object number : ob) { System.out.println("Number = " + number); } } }
输出结果
Number = 27 Number = 11 Number = 44 排序的对象数组是: Number = 11 Number = 27 Number = 44