vimwiki

Java arrays

Creating

// declare it without allocating space (does not initialised it)
int[] myNumbers;
String[] myStrings;

// declare and initialised (can be use after the above version)
int[] numbersArray = {1, 12, 32, 3};

// declare an empty array of 10 elements
int[] myArray = new int[10];

Accessing

myArray[2]

Changing value

myArray[2] = newValue;

Get length

myArray.length

2D array

```java // creating int[][] nums; int[][] nums = {{10, 2, 3}, {3, 21, 4}, {1,3,5}};

// creating empty int[][] = new int[2][3];

// accessing nums[1][3];