一、前言
代码:
//给定一个数组
int[] arr = {234,312,32,1321,321,43};
int[] arr1 = new int[6];
int[] arr2 = {1,3,7,8,32,432,432};
二、复制
1、arraycopy完成数组的复制
//复制arr源数组,srcPos(0)源数组中起点的位置,arr1目标数组,desPos(0)目标数组中的起始位置,length(6)要复制的数组元素的数量
System.arraycopy(arr,0,arr1,0,6); //[234, 312, 32, 1321, 321, 43]
2、copyof完成数组的复制
int[] newArr = Arrays.copyOf(arr2,6); //第二个是newLength
System.out.println(Arrays.toString(newArr)); //[1, 3, 7, 8, 32, 432]
3、copyOfRange完成数组的复制
int[] newArr2 = Arrays.copyOfRange(arr2,1,4); // 1 -4的区间
System.out.println(Arrays.toString(newArr2)); //[3, 7, 8]
三、遍历数组
1、二分查找遍历
System.out.println(Arrays.binarySearch(arr1,32)); //查找32这个值对应的索引值
2、返回的是一个字符串类型的数组
System.out.println(Arrays.toString(arr)); //[234, 312, 32, 1321, 321, 43]
三、比较数组equals
1、比较两个数据的值是否相等
int[] arr3 = {1,2,3,4,5223,4343,32};
int[] arr4 = {1,2,3,4,5223,4343,32};
System.out.println(Arrays.equals(arr3,arr4)); //比较的是值,也可以自己重写定义
System.out.println(arr3 == arr4); //比较的是左右地址
四、数组的填充fill
1、数组的填充
int[] arr5 = {1,2,3,4,5,67};
Arrays.fill(arr5,10);
System.out.println(Arrays.toString(arr5)); //[10, 10, 10, 10, 10, 10]
标签:Java,int,32,常见,System,Arrays,数组,out
From: https://www.cnblogs.com/new-one/p/17817645.html