一个数组的内存图
package com.besttest.class1;
public class Demo01Array {
public static void main(String[] args) {
int [] arr1= new int[3];
System.out.println(arr1); //地址值
System.out.println(arr1[0]);
System.out.println(arr1[1]);
System.out.println(arr1[2]);
//改变数组当中元素的内容
arr1[1]=10;
arr1[2]=20;
System.out.println(arr1[0]);
System.out.println(arr1[1]);
System.out.println(arr1[2]);
}
}
两个数组的内存图
package com.besttest.class1;
public class Demo01Array {
public static void main(String[] args) {
int [] arr1= new int[3];
System.out.println(arr1); //地址值
System.out.println(arr1[0]);
System.out.println(arr1[1]);
System.out.println(arr1[2]);
//改变数组当中元素的内容
arr1[1]=10;
arr1[2]=20;
System.out.println(arr1[0]);
System.out.println(arr1[1]);
System.out.println(arr1[2]);
int [] arr2= new int[3];
System.out.println(arr2); //地址值
System.out.println(arr2[0]);
System.out.println(arr2[1]);
System.out.println(arr2[2]);
//改变数组当中元素的内容
arr2[1]=10;
arr2[2]=20;
System.out.println(arr2[0]);
System.out.println(arr2[1]);
System.out.println(arr2[2]);
}
}
两个引用指向同一个数组
package com.besttest.class1;
public class Demo01Array {
public static void main(String[] args) {
int [] arr1= new int[3];
System.out.println(arr1); //地址值
System.out.println(arr1[0]);
System.out.println(arr1[1]);
System.out.println(arr1[2]);
//改变数组当中元素的内容
arr1[1]=10;
arr1[2]=20;
System.out.println(arr1[0]);
System.out.println(arr1[1]);
System.out.println(arr1[2]);
//将arr1数组的地址值赋值给arr2
int [] arr2= arr1;
System.out.println(arr2); //地址值
System.out.println(arr2[0]);
System.out.println(arr2[1]);
System.out.println(arr2[2]);
//改变数组当中元素的内容
arr2[1]=100;
arr2[2]=200;
System.out.println(arr2[0]);
System.out.println(arr2[1]);
System.out.println(arr2[2]);
}
}