Skip to content

Tag Archives: Java-Map-Programs

Map size() method in Java is used to get the total number entries i.e, key-value pair. So this method is useful when you want total… Read More
Given a map in Java, the task is to find out the entry in this map with the highest key. Examples: Input: Map = {ABC… Read More
Given a map, the task is to clone that map. Following are the 5 different ways to Clone a Map in Java. Example: {1=Geeks, 2=For,… Read More
ArrayList is a part of collection framework and is present in java.util package. It provides us dynamic arrays in Java. Though, it may be slower… Read More
By default TreeMap elements in Java are sorted in ascending order of keys. However, we can create the TreeMap in reverse order using Collections.reverseOrder() method… Read More
Given a HashMap and a key in Java, the task is to check if this key exists in the HashMap or not. Examples: Input: HashMap:… Read More
HashSet is implementation of Set Interface which does not allow duplicate value. The main thing is, objects that are stored in HashSet must override equals()… Read More
Given a HashMap and a value in Java, the task is to remove an entry from this HashMap using the value, while iterating over it.… Read More
Given a HashMap and a key in Java, the task is to remove an entry from this HashMap using the key, while iterating over it.… Read More
Given a Stream of Map in Java, the task is to Flatten the Stream using forEach() method. Examples: Input: map = {1=[1, 2], 2=[3, 4,… Read More
Given a Map with null values in it, the task is to replace all the null values with a default value. Examples: Input: map =… Read More
The List is a child interface of Collection. It is an ordered collection of objects in which duplicate values can be stored. Since List preserves… Read More
Given an integer array, sort the array according to the frequency of elements in decreasing order, if frequency of two elements are same then sort… Read More
Given example shows how to sort user defined objects TreeMap, you can sort the keys based on the logic provided inside the method. Given a… Read More
HashMap is a part of Java’s collection since Java 1.2. It provides the basic implementation of Map interface of Java which stores the data in… Read More