Maps in Java: Difference between revisions
From charlesreid1
No edit summary |
|||
| Line 9: | Line 9: | ||
==AbstractMap== | ==AbstractMap== | ||
The top level class is an abstract class called AbstractMap.java: http://hg.openjdk.java.net/jdk8/jdk8/jdk/file/ff6c76f7733e/src/share/classes/java/util/AbstractMap.java | The top level class is an abstract class called AbstractMap.java. | ||
Source: http://hg.openjdk.java.net/jdk8/jdk8/jdk/file/ff6c76f7733e/src/share/classes/java/util/AbstractMap.java | |||
Docs: https://docs.oracle.com/javase/7/docs/api/java/util/AbstractMap.html | |||
==Map== | ==Map== | ||
Revision as of 05:15, 21 June 2017
Notes
Maps are implemented in Java as part of the Collections framework. These are notes from the source.
Here is a link to the OpenJDK source code, util module: http://hg.openjdk.java.net/jdk8/jdk8/jdk/file/ff6c76f7733e/src/share/classes/java/util/
The Java Collections framework provides a number of different useful map-related classes.
AbstractMap
The top level class is an abstract class called AbstractMap.java.
Docs: https://docs.oracle.com/javase/7/docs/api/java/util/AbstractMap.html
Map
Next is the base map class Map.java: http://hg.openjdk.java.net/jdk8/jdk8/jdk/file/ff6c76f7733e/src/share/classes/java/util/Map.java
HashMap
HashMap is a faster, O(1) map that uses a hash table to store data but stores the data in an unsorted fashion. HashMap.java Link: http://hg.openjdk.java.net/jdk8/jdk8/jdk/file/ff6c76f7733e/src/share/classes/java/util/HashMap.java
TreeMap
TreeMap is a slower, O(log N) map that uses a tree structure to store data in a sorted fashion. This provides faster access to max/min of data. TreeMap.java Link: http://hg.openjdk.java.net/jdk8/jdk8/jdk/file/ff6c76f7733e/src/share/classes/java/util/TreeMap.java
LinkedHashMap
There is also a LinkedHashMap, which implements a Hash Map using a linked structure: http://hg.openjdk.java.net/jdk8/jdk8/jdk/file/ff6c76f7733e/src/share/classes/java/util/LinkedHashMap.java
Hashtable
The Hashtable class also provides a slimmed down version of a map - a straight hash table implementation arbitrary key-value types: http://docs.oracle.com/javase/7/docs/api/java/util/Hashtable.html