赞
踩
toString(数组类型[] a)
int[] arr = {8,1,2,3,4};
System.out.println(Arrays.toString(arr));
//[8,1, 2, 3, 4]
binarySearch(数组类型[] a, 指定类型 key)
int[] arr = {8,1,2,3,4,5,6,7};
System.out.println(Arrays.binarySearch(arr, 3));
//3
sort(数组类型[] a)
int[] arr = {8,1,2,3,4};
Arrays.Sort(arr1);
System.out.println(Arrays.toString(arr));
//[1, 2, 3, 4, 8]
compare(数组类型[] a, 数组类型[] b)
int[] arr1 = {8,1,2,3,4};
int[] arr2 = {8,1,2,3,4};
int[] arr3 = {100,0,2,3,4};
System.out.println(Arrays.compare(arr1, arr2));
// 0
System.out.println(Arrays.compare(arr1, arr3));
//-1
System.out.println(Arrays.compare(arr3, arr1));
//1
mismatch(数组类型[] a, 数组类型[] b)
int[] arr1 = {8,1,2,3,4};
int[] arr2 = {8,1,2,3,4};
int[] arr1 = {8,1,5,3,4};
System.out.println(Arrays.mismatch(arr1,arr2));
//-1
System.out.println(Arrays.mismatch(arr1,arr3));
//2
equals(数组类型[] a, 数组类型[] a2)
int[] arr1 = {8,1,2,3,4};
int[] arr2 = {8,1,2,3,4};
System.out.println(Arrays.equals(arr1, arr2));
//true
hashCode(数组类型[] a)
int[] arr2 = {8,1,2,3,4};
System.out.println(Arrays.hashCode(arr2));
copyOf(数组类型[] original, 数组类型 newLength)
int[] arr1 = {8,1,2,3,4};
System.out.println(arr1.length);
//5
int[] arr4 = Arrays.copyOf(arr1, 10);
System.out.println(arr4.length);
//10
copyOfRange(数组类型[] original, int from, int to)
int[] arr1 = {8,1,2,3,4};
System.out.println(Arrays.toString(arr1));
//[8, 1, 2, 3, 4]
int[] arr4 = Arrays.copyOfRange(arr1, 2, 5);
System.out.println(Arrays.toString(arr4));
//[2, 3, 4]
fill(数组类型[] a, 数组类型 val)
int[] arr4 = new int[4];
Arrays.fill(arr4, 2);
System.out.println(Arrays.toString(arr4));
//[2, 2, 2, 2]
fill(数组类型[] a, int fromIndex, int toIndex, 数组类型 val)
int[] arr1 = {8,1,2,3,4};
Arrays.fill(arr1, 1, 3, 8);
System.out.println(Arrays.toString(arr1));
//[8, 8, 8, 3, 4]
setAll(int[] array, IntUnaryOperator generator)
int[] arr1 = {8,1,2,3,4};
Arrays.setAll(arr1, new IntUnaryOperator() {
@Override
public int applyAsInt(int operand) {
return operand*5;
}
});
System.out.println(Arrays.toString(arr1));
//[0, 5, 10, 15, 20]
parallelPrefix(int[] array, IntBinaryOperator op)
int[] arr1 = {8,1,2,3,4};
Arrays.parallelPrefix(arr1, new IntBinaryOperator() {
@Override
public int applyAsInt(int left, int right) {
//left:前一个索引对应的元素
//right:当前索引对应的元素
return left+right;
}
});
System.out.println(Arrays.toString(arr1));
//[8, 9, 11, 14, 18]
parallelSetAll(int[] array, IntUnaryOperator generator)
int[] arr1 = {8,1,2,3,4};
Arrays.parallelSetAll(arr1, new IntUnaryOperator() {
@Override
public int applyAsInt(int operand) {
return operand*2;
}
});
System.out.println(Arrays.toString(arr1));
//[0, 2, 4, 6, 8]
parallelSort(int[] a)
int[] arr1 = {8,1,2,3,4};
Arrays.parallelSort(arr1);
System.out.println(Arrays.toString(arr1));
//[1, 2, 3, 4, 8]
deepEquals(Object[] a1, Object[] a2)
Integer[] arr1 = {8,1,2,3,4};
Integer[] arr2 = {8,1,2,3,4};
System.out.println(Arrays.deepEquals(arr1, arr2));
//true
deepHashCode(Object[] a)
Integer[] arr1 = {8,1,2,3,4};
System.out.println(Arrays.deepHashCode(arr1));
//36049129
deepToString(Object[] a)
Integer[] arr1 = {8,1,2,3,4};
System.out.println(Arrays.deepToString(arr1));
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。