November 2006
Intermediate to advanced
224 pages
3h 29m
English
HashMap map = new HashMap(); map.put(key1, obj1); map.put(key2, obj2); map.get(key3, obj3); |
In this phrase, we use a HashMap to create a mapped collection of objects. The HashMap has a put() method that accepts two parameters. The first parameter is a key value, and the second parameter is the object you want to store in the map. So, in this phrase, we are storing three objects—obj1, obj2, and obj3—indexed by keys—key1, key2, and key3, respectively. The HashMap class is one of the most commonly used Java classes. In a HashMap, the objects put into a map should all be of the same class type. So if obj1 is a String object, then obj2 and obj3 should also be String objects.
To retrieve the objects that you put into the ...
Read now
Unlock full access