Java Map

Java Map computeIfAbsent()

The Map.computeIfAbsent() method computes the mapped value for a key using a mapping function if the specified key does not exist in the Map or is mapped to a null value. It has been added as the default method in the Map interface in Java 8. 1. When to Use the computeIfAbsent() Method? 1.1. When Mapper Function …

Java ConcurrentSkipListMap

Learn the Java ConcurrentSkipListMap and the major differences between ConcurrentSkipListMap and other Map implementations.

Convert List to Map in Java

Learn to convert a List to a Map in Java using Streams, Commons collections, and Guava including Multimap class for duplicate list items.

Inverting a Map In Java

This Java tutorial will teach us how to invert a given Map using different techniques. We will learn to invert Maps with unique values and create Multimap when there are duplicate values. 1. What is an Inverted Map? An inverted Map <V, K> is an instance of the original Map<K, …

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.

Get SubMap From Map In Java

A submap is a portion or part of a map between the keys of a specific range. Learn how to get submap from map in Java with different ways.

Java EnumMap with Examples

Learn to create and work with the Java EnumMap in detail, difference between EnumMap and HashMap and the practical usecases for the same.

Java Nested Map with Examples

A nested Map is Map inside another Map. Learn to create a nested HashMap and add, remove and iterate over the elements with examples.

Java TreeMap vs HashMap

Learn the differences between TreeMap and HashMap in Java as both implements the Map interface but differ in functionality and performance.

Guide to Java IdentityHashMap

IdentityHashMap implements the Map interface and has almost the same features as HashMap. It uses reference equality on key search operations.

Guide to Java WeakHashMap

Learn about the Java WeakHashMap, strong & weak references with examples. Also, learn the differences between WeakHashMap and HashMap.

Java TreeMap class

Java TreeMap class stores key-value pairs very similar to the HashMap class. The difference is that TreeMap provides an efficient way to store key/value pairs in sorted order. The TreeMap class is a red-black tree-based NavigableMap implementation. This Java TreeMap tutorial will teach us about TreeMap class, methods, usecases, and …

Java LinkedHashMap class

LinkedHashMap in Java is used to store key-value pairs very similar to HashMap class. Difference is that LinkedHashMap maintains the order of elements inserted into it while HashMap is unordered. In this Java collection tutorial, we will learn about LinkedHashMap class, it’s methods, usecases and other important details. Table of …

Clone a HashMap – Shallow and Deep Copy

Learn to create clone of a HashMap in Java. We will see the java programs to create shallow copy and deep copy of a HashMap. 1. Creating a Shallow Copy of Map We can create a shallow copy of a given HashMap in two ways. The first uses the clone() …

How to Join or Merge Two Maps in Java

Learn merging two hashmaps in both cases – ignoring duplicate keys (overwrites the value) or handling duplicate keys. 1. Merge Two HashMaps Ignoring Duplicate Keys This one is a simple solution. Use firstMap.putAll(secondMap) method that copies all of the mappings from the secondMap to firstMap. As we know hashmap does …

How to Compare Two Maps in Java

Learn to compare two Java Maps for the equality of their entries, key and values, and find the Map differences using Guava’s MapDifference API.

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.