Java Map

Maps in Java are the core building blocks of the Collections framework. The following tutorials will teach us the basics of working with different maps in Java.

1. Basics

2. Difference Between

3. Map Classes

4. Advance Topics

5. Performance

The following table shows the relative performance of the different implementations of Map interface. Note that the final choice of Map class has to be influenced more by the functional requirements of the application and the concurrency properties. For example,

  • HashMap is preferred for simple usecases with few entries.
  • EnumMap should always (and only) be used for mapping from enums.
  • For a sorted map, use TreeMap where thread safety is not required, ConcurrentSkipListMap otherwise.
Map ClassgetcontainsKeynext
TreeMapO(log n)O(log n)O(log n)
ConcurrentSkipListMapO(log n)O(log n)O(1)
Note: ‘h‘ is the table capacity.

Happy Learning !!

Comments are closed for this article!

About Us

HowToDoInJava provides tutorials and how-to guides on Java and related technologies.

It also shares the best practices, algorithms & solutions and frequently asked interview questions.