public class Arrays4_9_27 {
/**
* 数组的工具类
*/
public static void main(String[] args) {
// 定义一个a数组
int[] a = new int[]{3, 4 , 5, 6};
// 定义一个a2数组
int[] a2 = new int[]{3, 4 , 5, 6};
System.out.println("a数组和a2数组是否相等:"
+ Arrays.equals(a , a2));
int[] b = Arrays.copyOf(a, 6);
for (int i = 0; i < b.length; i++) {
System.out.print(" "+b[i]);
}
System.out.println();
System.out.println("b数组的元素为:"
+ Arrays.toString(b));
}
}
int[] a = new int[]{3,4,5,6};
int[] b = new int[]{93,683,9,2,8,5,4,433,87654};
//一般复制
int[] c = Arrays.copyOf(a, 6);
System.out.println(Arrays.toString(c));
//升序排列
Arrays.sort(b);
for (int i : b) {
System.out.print(" "+i);
}
System.out.println("-----折半(必须先排序)------");
System.out.println(Arrays.binarySearch(b,433));
//选择复制
int copyArr[] = Arrays.copyOfRange(b2, 1, 6);
for (int i : copyArr) {
System.out.print(" "+i);
}
//填充
double[] a2= new double[4];
Arrays.fill(a2,3.14);
for (double d : a2) {
System.out.print(" "+d);
}
//选择填充
long[] b1 = new long[6];
Arrays.fill(b1,3,5,7);
for (long l : b1) {
System.out.print(" "+l);
}