Arrays in Java
Fixed-size and primitive-friendly, with a utility class for the rest.
import java.util.Arrays;
int[] fib = { 1, 1, 2, 3, 5, 8, 13 };
System.out.println(fib.length + " values, third " + fib[2]);
System.out.println(Arrays.toString(fib));
// Arrays holds the utilities the array itself lacks
var middle = Arrays.copyOfRange(fib, 2, 5);
System.out.println(Arrays.toString(middle));
System.out.println(Arrays.binarySearch(fib, 8));
int[][] grid = new int[2][3];
grid[1][2] = 9;
System.out.println(grid[1][2]);
How it works
- Literal syntax initializes;
lengthand[2]read. Arrays.toString,copyOfRangeandbinarySearchfill the gaps.new int[2][3]is an array of arrays, indexed twice.
Keywords and builtins used here
intnewvar
The run, in numbers
- Lines
- 14
- Characters to type
- 437
- Tokens
- 144
- Three-star pace
- 90 tpm
At the three-star pace of 90 tokens a minute, this run takes about 96 seconds.
Step 1 of 4 in Collections, step 11 of 29 in Language basics.