Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - In java, after the array is passed into the function, new is used again. Will it change the array value?
In java, after the array is passed into the function, new is used again. Will it change the array value?
There is a data type in Java called reference type.

The array is a reference type. In fact, what you want to create with new is a reference type.

What is a reference type?

For example, you create a new array {1, 2, 3}, which actually operates like this in computer memory.

First, a variable named intArray is generated in memory, and an {1, 2,3} array is generated in another memory.

Then assign the memory address value of this array to the variable of this intArray. So the value you pass to the function is the address of that array.

Then the characteristics of this can be explained as follows:

If you build a city called intArray on the south seashore (address) of China, then you change its name to arrays and give it to another person (change ()) to take care of it, but he doesn't think this city is worthy of this name, so he builds a new city (new int[]) on the east seashore (address) of China and gives it the name of Shanghai.

Therefore, Guangzhou is as big as it is, and it has not changed in his hands. He went to Shanghai, so Guangzhou has not changed (so it still shows 1, 2, 3).

However, if he doesn't go to the east to build a new Shanghai city, but asks Guangzhou and Shanghai to manage it according to your requirements, the area of Guangzhou will be expanded by several hundred thousand square meters (aArray[0]=7). Then this southern coastal city really changed (as shown in Figures 7, 2 and 3).

In other words, the address is there, no matter what name you change to, as long as it is in the city with that address, it is the same.

ps:

If you print this array variable directly, a string will be printed.

Like this: "xx@xxx"

Among them, the @ symbol is preceded by the type of this instance, and the @ symbol is followed by the hash value of the memory address of the instance (just think of it as the address of the instance, and you will understand it later).