-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayTest.java
More file actions
45 lines (31 loc) · 914 Bytes
/
ArrayTest.java
File metadata and controls
45 lines (31 loc) · 914 Bytes
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
package array;
import org.junit.Test;
/*
>. once the size of array settled, can't change it any more
>. dimensions: 1 ,2
*/
public class ArrayTest {
public static void main(String[] args) {
// static initialization with items assigned
String[] names = new String[]{"A", "B", "ccc"};
// dynamic initialization, will assign item later
int[] ids = new int[3];
// call item
System.out.println(names[1]);
ids[0] = 1;
ids[1] = 3;
ids[2] = 2;
for (int i = 0; i < ids.length; i++) {
System.out.print(ids[i] + " ");
}
}
@Test
public void pointerTest(){
int[] nums = new int[5];
// the address where nums is pointing at
System.out.println(nums); // [I@deb6432
System.out.println(nums[0]); // 0
nums[1] = 1;
System.out.println(nums[1]);
}
}