How to Check if LinkedHashMap is Empty in Java? Last Updated : 11 Dec, 2020 Comments Improve Suggest changes Like Article Like Report The LinkedHashMap is just like HashMap with an additional feature of maintaining an order of elements inserted into it. HashMap provided the advantage of quick insertion, search, and deletion but it never maintained the track and order of insertion which the LinkedHashMap provides where the elements can be accessed in their insertion order. Here, Let's illustrate the different approaches for checking if the LinkedHashMap is empty or not. Example: Input : {3=Geeks, 2=For, 1=Geeks} Output: Given LinkedHashMap is not empty Input : {} Output: Given LinkedHashMap is empty1. Using the size() method : Create variable lhmSize.Store the value of the size of LinkedHashMap in it.If the size of the given LinkedHashMap is 0 then it is empty.Else it is not empty.Below is the implementation of the above approach: Java // Java Program check if LinkedHashMap is empty or not import java.util.LinkedHashMap; public class Main { public static void main(String[] args) { // create an instance of LinkedHashMap LinkedHashMap<Integer, String> hm1 = new LinkedHashMap<Integer, String>(); // Using size() method to make comparison System.out.println( "Given LinkedHashMap is " + (hm1.size() == 0 ? "empty" : "not empty")); // Add mappings using put method hm1.put(3, "Geeks"); hm1.put(2, "For"); hm1.put(1, "Geeks"); int lhmSize = hm1.size(); if (lhmSize == 0) System.out.println( "Given LinkedHashMap is empty"); else System.out.println( "Given LinkedHashMap is not empty"); } } OutputGiven LinkedHashMap is empty Given LinkedHashMap is not empty Time Complexity: O(1) 2. Using the isEmpty() method : Create boolean variable lhmSize.Store the return value of the isEmpty() method.If the size of the given LinkedHashMap is 0 then isEmpty() method will return true.Else method will return false.Below is the implementation of the above approach: Java // Java Program check if LinkedHashMap is empty or not import java.util.LinkedHashMap; public class Main { public static void main(String[] args) { // create an instance of LinkedHashMap LinkedHashMap<Integer, String> hm1 = new LinkedHashMap<Integer, String>(); // Using isEmpty() method to make comparison System.out.println( "Given LinkedHashMap is " + (hm1.isEmpty() ? "empty" : "not empty")); // Add mappings using put method hm1.put(3, "Geeks"); hm1.put(2, "For"); hm1.put(1, "Geeks"); boolean lhmSize = hm1.isEmpty(); if (lhmSize) System.out.println( "Given LinkedHashMap is empty"); else System.out.println( "Given LinkedHashMap is not empty"); } } OutputGiven LinkedHashMap is empty Given LinkedHashMap is not empty Time Complexity: O(1) Comment More infoAdvertise with us Next Article How to Check if LinkedHashMap is Empty in Java? rbbansal Follow Improve Article Tags : Java Java Programs Java-LinkedHashMap Practice Tags : Java Similar Reads How to Check if LinkedHashMap Contains a value in Java? LinkedHashMap is a predefined class in Java which is similar to HashMap, contains key and its respective value unlike HashMap, In LinkedHashMap insertion order is preserved. The task is to check if LinkedHashMap contains any value in java. to check we have to iterate through our LinkedHashMap and if 3 min read How to iterate LinkedHashMap in Java? LinkedHashMap class extends HashMap and maintains a linked list of the entries in the map, in the order in which they were inserted. This allows insertion-order iteration over the map. That is, when iterating a LinkedHashMap, the elements will be returned in the order in which they were inserted. Th 2 min read Checking if Element Exists in LinkedHashSet in Java The Java.util.LinkedHashSet.contains() method is used to check whether a specific element is present in the LinkedHashSet or not. So basically it is used to check if a Set contains any particular element. The contains a method of the LinkedHashSet class returns true if the specified element is found 1 min read How to Get a Value From LinkedHashMap by Index in Java? LinkedHashMap is a predefined class in Java which is similar to HashMap, contain key and its respective value unlike HashMap, In LinkedHashMap insertion order is preserved. The task is to get value from LinkedHashMap by their Index in other words, an order of their insertion. As an advantage of Link 4 min read How to Remove Elements from a LinkedHashMap in Java? A LinkedHashMap is a part of the Collection Framework from java.util package Java and is similar to a HashMap, except that a LinkedHashMap preserves the insertion order among the keys/entries. In this article, we will look at how to remove the elements from a LinkedHashMap in Java. Program to Remove 2 min read How to Find the Element Index in LinkedHashSet in Java? LinkedHashSet is used to store distinct items and get the items in which order they were inserted in Java. LinkedHashSet does not store values based on the index. But there are some methods to find the element index in LinkedHashSet in Java. Method 1: (By converting LinkedHashSet to ArrayList) To fi 4 min read How to Merge Two LinkedHashMaps in Java? In Java, LinkedHashMap is a class that extends HashMap and maintains the order of elements based on the order of insertion. Merging two LinkedHashMaps involves combining their key-value pairs while ensuring that the order is preserved. In, this article we will explore different approaches to merging 3 min read How to Iterate LinkedHashMap in Reverse Order in Java? The LinkedHashMap is used to maintain an order of elements inserted into it. It provides where the elements can be accessed in their insertion order. A LinkedHashMap contains values based on the key. It implements the Map interface and extends the HashMap class. It contains only unique elements or m 6 min read How to Get All the Values of the LinkedHashMap in Java? LinkedHashMap is a predefined class in Java that is similar to HashMap, contains key and its respective value, unlike HashMap. In LinkedHashMap insertion order is preserved. The task is to get all the values present in our LinkedHashMap that is linked with their respective key. Use Iteration or pred 4 min read Like