int[] arr1 = {1,2,3,4,5,6};
int[] arr2 = Arrays.copyOf(arr1, 8);
System.out.println(Arrays.toString(arr2));
int[] arr3 = new int[8];
//被复制的数组 从哪个位置开始复制 复制到的数组 从哪个位置开始粘贴 复制的长度
System.arraycopy( arr1 , 1 , arr3 , 1 , 2);
System.out.println(Arrays.toString(arr3));
//普通for循环
int[] arr1 = {1,2,3,4,5,6};
for (int j = 0; j < i.length ; j++) {
System.out.println(i[j]);
}
//高效for循环&foreach循环
Integer[] arr2 = {1,2,3,4,5,6};
for (Integer integer: arr2
) {
System.out.println(integer);
}
//嵌套for循环
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
System.out.println(i+":"+j);
}
}
for (int i = 0; i <= 3; i++) {
for (int j = 0; j <= 1 ; j++) {
if (i == 2){
continue;
System.out.println("hello");
}
System.out.println(i+""+j);
}
}
var arr1 = ["a",1,'q'];
var arr2 = new Array("hello","world");
var arr3 = new Array(3);
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)