Use a Java HashMap

HashMap is a funny name. The “hash” part refers to how it works internally; it really has nothing to do with how you use it.

But the “map” part is about what you’d think: it maps a key, which can be anything, to a value, which can also be anything.

Other languages might call this a dictionary, an associative array or some kind of associative memory. They all mean the same thing. With an array, you use an integer as the index. With a HashMap, you can use any object as the key, especially Strings (see Figure 2, A HashMap).

images/HashMap.png
Figure 2. A HashMap

We’ll use this a lot in the plugins. It’s a great way to keep track of players, ...

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.