stream
stream(int[] array)
返回顺序IntStream与指定的数组作为源。
stream(int[] array, int startInclusive, int endExclusive)
返回顺序IntStream与指定的数组作为源的指定范围。
asList方法
static <T> List<T> asList(T... a)
返回由指定数组支持的固定大小的列表。
二分查找
binarySearch(int[] a, int key)
使用二叉搜索算法搜索指定的int数组的指定值。
binarySearch(int[] a, int fromIndex, int toIndex, int key)
使用二叉搜索算法搜索指定值的指定数组的范围。
复制
copyOf(int[] original, int newLength)
复制指定的数组,用零截取或填充(如有必要),以便复制具有指定的长度。
public class TestClass {
public static void main(String[] args) {
int[] a = {1,2,3};
int[] b = Arrays.copyOf(a, 2);
for(int i=0;i<2;i++) {
System.out.println(b[i]);
}
//1,2
int[] c = Arrays.copyOf(a, 5);
for(int i=0;i<5;i++) {
System.out.println(c[i]);
}
//1,2,3,0,0
}
}
copyOfRange(int[] original, int from, int to)
将指定数组的指定范围复制到新数组中。
比较equals
equals(int[] a, int[] a2)
如果两个指定的int数组彼此 相等 ,则返回 true 。
public class TestClass {
public static void main(String[] args) {
int[] a = {1,2,3};
int[] b = {1,2,3};
if(Arrays.equals(a, b)) {
System.out.println("equal");
}
}
}
填充fill
fill(int[] a, int val)
将指定的int值分配给指定的int数组的每个元素。
fill(int[] a, int fromIndex, int toIndex, int val)
将指定的int值分配给指定的int数组的指定范围的每个元素。
public class TestClass {
public static void main(String[] args) {
int[] a = {1,2,3};
Arrays.fill(a, 5);
for(int i=0;i<3;++i) {
System.out.println(a[i]);
}//5,5,5
}
}
排序
sort(int[] a)
按照数字顺序排列指定的数组。
sort(int[] a, int fromIndex, int toIndex)
按升序排列数组的指定范围。
sort(T[] a, Comparator<? super T> c)
根据指定的比较器引发的顺序对指定的对象数组进行排序。
sort(T[] a, int fromIndex, int toIndex, Comparator<? super T> c)
根据指定的比较器引发的顺序对指定的对象数组的指定范围进行排序。