Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content
HowToDoInJava
  • Java
  • Spring AI
  • Spring Boot
  • Hibernate
  • JUnit 5
  • Interview

Java Map

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

Lokesh Gupta

August 15, 2024

Java HashMap, Series
Java Map, Series
Java Collections

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

  • Intro to Java HashMap
  • How HashMap works in Java?
  • How to clone HashMap – Shallow and Deep Copy
  • How to Synchronize HashMap
  • How to Join or Merge Two Maps
  • How to Compare Two HashMaps
  • Get SubMap From Map
  • Creating Nested Maps
  • Creating Immutable and Unmodifiable Maps

2. Difference Between

  • Difference between TreeMap vs HashMap
  • Difference between HashMap vs Hashtable

3. Map Classes

  • Java IdentityHashMap
  • Java ConcurrentMap
  • Java WeakHashMap
  • Java TreeMap
  • Java LinkedHashMap
  • Java EnumMap

4. Advance Topics

  • Designing a Good Custom Key for HashMap
  • Performance Comparison of Different Ways to Iterate over HashMap
  • Creating a Java Map with Case-Insensitive Keys
  • Inverting a Map
  • Convert Object to Map
  • Convert a Map to Array, List or Set

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
HashMapO(1)O(1)O(h/n)
LinkedHashMapO(1)O(1)O(1)
IdentityHashMapO(1)O(1)O(h/n)
EnumMapO(1)O(1)O(1)
TreeMapO(log n)O(log n)O(log n)
ConcurrentHashMapO(1)O(1)O(h/n)
ConcurrentSkipListMapO(log n)O(log n)O(1)
Note: ‘h‘ is the table capacity.

Happy Learning !!

Java HashMap

  • How does HashMap Works?
  • Custom Key Design
  • Synchronize HashMap
  • Merge HashMaps
  • Compare HashMaps
  • Iterating Over Maps
  • Cloning a Map

Table of Contents

  • 1. Basics
  • 2. Difference Between
  • 3. Map Classes
  • 4. Advance Topics
  • 5. Performance
Photo of author

Lokesh Gupta

A fun-loving family man, passionate about computers and problem-solving, with over 15 years of experience in Java and related technologies. An avid Sci-Fi movie enthusiast and a fan of Christopher Nolan and Quentin Tarantino.
Follow on Twitter Portfolio

Previous

Creating a Java Map with Case-Insensitive Keys

Next

Java List

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.

Tutorial Series

OOP

Regex

Maven

Logging

TypeScript

Python

Meta Links

About Us

Advertise

Contact Us

Privacy Policy

Our Blogs

REST API Tutorial

Follow On:

  • Github
  • LinkedIn
  • Twitter
  • Facebook
Copyright © 2026 | Sitemap