Use a Java Array

While variables with individual values are useful and common, sometimes you need more than that. You need to keep track of all the players in the system, or one player’s inventory items, or a to-do list, or a grocery list, or a homework list.

Java has you covered. There are several different ways to keep and access piles of data. We’re going to focus on a few: the simple Array, the classier ArrayList, and the remarkably handy if somewhat alien HashMap (covered in the next chapter). First up, the Array.

There are actually a few different Array-like collections in Java, including Array, Vector, LinkedList, and ArrayList types. They each work differently on the inside, are stored slightly differently, and perform differently ...

Get Learn to Program with Minecraft Plugins, 2nd Edition 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.