Java Syntax

1. About Array

1.1 Array Declaration

(1) int [] a;
(2) int a [];
 The first declaration is recommended because it is easy to see that variable ‘a’ is an integer array. At this point, ‘a’ does not point to a specific piece of heap memory. So its default value is null.

1.2 Array Initialization

1.2.1 Static Initialization
int[] a = new int [5];
a[0] = 0;
a[1] = 1;

‘new’ means to create a new space on the heap.

1.2.2 Dynamic Initialization
int[] a = new int []{
     1, 2, 3};
int[] a = {
     1, 2, 3};

1.3 Anonymous Array

System.out.printIn(new int[]{
     1, 2, 3});

 Anonymous array is an array without name. It is same as an ordinary array but not assigned to any variable.

你可能感兴趣的:(Java,java)