方法sort(int [] a,int fromIndex,int toIndex)在Java中做什么?
java.util.Arrays类的 sort(int[]a,intfromIndex,inttoIndex)方法将指定整数值数组的指定范围按升序排序。要排序的范围从索引fromIndex(包括)到索引toIndex(不包括)。
示例
import java.util.Arrays; public class ArrayDemo { public static void main(String[] args) { int iArr[] = {3, 1, 2, 18, 10}; for (int number : iArr) { System.out.println("Number = " + number); } Arrays.sort(iArr, 0, 3); System.out.println("int array with some sorted values(0 to 3) is:"); for (int number : iArr) { System.out.println("Number = " + number); } } }
输出结果
Number = 3 Number = 1 Number = 2 Number = 18 Number = 10 int array with some sorted values(0 to 3) is: Number = 1 Number = 2 Number = 3 Number = 18 Number = 10