© Adam L. Davis 2020
A. L. DavisModern Programming Made Easyhttps://doi.org/10.1007/978-1-4842-5569-8_5

5. Arrays, Lists, Sets, and Maps

Adam L. Davis1 
(1)
Oviedo, FL, USA
 

So far, I’ve only talked about single values, but in programming, you often have to work with large collections of values. For this, we have many data structures that are built into the language. These are similar for Java, Groovy, Scala, and even JavaScript.

Arrays

An array is a fixed size collection of data values.

You declare an array type in Java by appending [] to the type. For example, an array of ints is defined as int[].
1   int[] vampireAges = new  int[10]; // ten vampires
Setting and accessing the values in an array uses the same square bracket syntax, such as the following: ...

Get Modern Programming Made Easy: Using Java, Scala, Groovy, and JavaScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.