Skip to content

Latest commit

 

History

History
17 lines (11 loc) · 714 Bytes

File metadata and controls

17 lines (11 loc) · 714 Bytes

Initialization with Size

The Nintendo GameBoy had a screen resolution of 160 x 144. To store the value of each pixel1 you would need an array 23,040 items long.

To support this without you writing the word false 23,040 times, arrays can be made just by giving a size and skipping the initializer.

boolean[] pixels = new boolean[23040];

So you have to say new followed by the type of element in the array, [, the size of the array and ].

Footnotes

  1. The original GameBoy wasn't actually just black and white. It supported 7 shades of gray, so a boolean wouldn't technically be enough to represent a pixel's state. You'd have to use something with at least 8 states, not just 2.