????为了方便我们对数组进行操作,系统提供一个类Arrays,我们将它当做工具类来使用。
import java.util.Arrays;
public class ArraysUtils {
public static void main(String[] args) {
int[] arr=new int[]{1,2,3,4,5,8,6,7};
System.out.println(Arrays.toString(arr));
Arrays.sort(arr);
System.out.println(Arrays.toString(arr));
System.out.println(Arrays.binarySearch(arr, 6));
int[] ints = Arrays.copyOf(arr, 5);
System.out.println(Arrays.toString(ints));
int[] ints1 = Arrays.copyOfRange(arr, 2, 8);
System.out.println(Arrays.toString(ints1));
System.out.println(Arrays.equals(arr, ints));
Arrays.fill(arr,8);
System.out.println(Arrays.toString(arr));
}
}
|