My Findings on HashMaps:
- A Map is one type of Collection in Java. Collections are used to hold a bunch of objects. Different Collections let you look up your objects in different ways.
- The special thing about Maps is that the way you look up your objects in a Map is with another object.
- A Map is like an associative array in PHP. It is a container for key - value pairs.
- To get values out of a Map, you iterate through the Map's keys and use the get() method to get the value associated with that key back out.
- Map is the interface, Hashmap or TreeMap is the implementation of that interface, just like ArrayList is an implementation of List. So, to make a new HashMap, you would say Map myHashMap = new HashMap();
- A HashMap uses the hashCode() method available to all Java objects to take the hashCode of your object so that it can quickly find it when you want it.
- with a HashMap, your objects will not be sorted the way you expect
- with a TreeMap, the objects are sorted in a way that makes sense.
12:20:32 PM
|
|