Java中数组的地址问题(hashCode解析):

2022-11-29 14:26:21 浏览数 (1)

Java中数组的地址问题(hashCode解析):

代码语言:javascript复制
import java.util.Arrays;

public class Action1 {

	public static void main(String[] args) {
		//1、初始数组
		int [] array0= {5,9,9,9,65,65,95,9,5,6,69,6,65,899};
		System.out.println("0->生成地址:t" array0.hashCode());
		//2、赋值数组
		int [] array1=array0;
		System.out.println("1->未生成新地址:t" array1.hashCode());
		//3、创建数组相当于new
		int[] array2 = Arrays.copyOf(array0, array0.length);
		System.out.println("2->生成新地址:t" array2.hashCode());
		//4、new创建数组,相当于array2的Arrays.copyOf
		int[] array3 = new int[array0.length];
		for (int i = 0; i < array0.length; i  ) {
			array3[i]=array0[i];
		}
		System.out.println("3->生成新地址:t" array3.hashCode());
	}
}

效果:

0 人点赞