1. Basic data type assignment, this value is concrete data, and does not affect each other.
int n1 = 2; int n2 = n1;
Copy the code
  1. Arrays are passed by reference by default, and assigned values are addresses.
  • Look at an example and analyze the memory diagram of array assignment. ArrayAssign.java
int[] arr1 = {1.2.3};
int[] arr2 = arr1;
Copy the code
	// The basic data type is assigned to a value copy
	//n2 does not affect the value of n1
	int n1 = 10;
	int n2 = n1;
	
	n2 = 80;
	System.out.println("n1=" + n1);/ / 10
	System.out.println("n2=" + n2);/ / 80
	
	// Arrays are passed by reference by default. The assigned value is address, and the assignment method is reference assignment
	// is an address. Changes in ARR2 affect ARR1
	int[] arr1 = {1.2.3};
	int[] arr2 = arr1;// assign arr1 to arr2
	arr2[0] = 10;
	
	// look at the arr1 value
	System.out.println("==== Elements of arr1 ====");
	for(int i = 0; i < arr1.length; i++) {
		System.out.println(arr1[i]);/ / 10, 2, 3
	}
	
	System.out.println("==== Elements of arr2 ====");
	for(int i = 0; i < arr2.length; i++) {
		System.out.println(arr2[i]);/ / 10, 2, 3
	}
Copy the code