-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathArrayTest.java
52 lines (28 loc) · 1.43 KB
/
ArrayTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import java.util.Arrays;
public class ArrayTest {
String[] arr = {"ABC", "DEF", "XYZ"};
public static void changeArray(String[] alocalRef, ArrayTest aObject) {
System.out.println("before: ");
System.out.println("\t" + Arrays.toString(alocalRef));
System.out.println("\t" + System.identityHashCode(alocalRef));
alocalRef[2] = "GHI";
System.out.println("after: ");
System.out.println("\t" + Arrays.toString(alocalRef));
System.out.println("\t" + System.identityHashCode(alocalRef));
System.out.println("before: ");
System.out.println("\t" + Arrays.toString(aObject.arr));
System.out.println("\t" + System.identityHashCode(aObject.arr));
alocalRef[2] = "GHI";
System.out.println("after: ");
System.out.println("\t" + Arrays.toString(aObject.arr));
System.out.println("\t" + System.identityHashCode(aObject.arr));
}
public static void main(String[] args) {
ArrayTest test1 = new ArrayTest();
System.out.println("Before code = " + System.identityHashCode(test1));
System.out.println("Before code = " + System.identityHashCode(test1.arr));
test1.changeArray(test1.arr, test1);
System.out.println("After arr = " + System.identityHashCode(test1));
System.out.println("After arr = " + System.identityHashCode(test1.arr));
}
}