Arrays & for-each loop
for(int value : hourCounts){
System.out.println(“ : “ + value);
}
Arrays can be used with for-each loop but it doesn’t provide access to a loop counter variable thus old for-loop is preferred
Which loop should you use?
Conditional operator
for(int cellValue state){
System.out.print(cellValue == 1 ? ‘+’ : ‘ ‘);
}
System.out.println();
lookup tables
Array initialiser
Arrays of more than one dimension
Setting up 2D arrays
cells = new Cell[numRows][numCols];
for(int row = 0; row < numRows; row++) {
for (int col = 0; col < numCols; col++) {
cells[row][col] = new Cell();
}
}
setupNeighbors();