How to Check the LinkedHashMap Size in Java? Last Updated : 07 Jan, 2021 Comments Improve Suggest changes Like Article Like Report Size of LinkedHashMap can be obtained in multiple ways like by using an inbuilt function and by iterating through the LinkedHashMap. Example: Input : List : [1 : "John", 2 : "Tom", 3 : "Tim"] Output: 3 Input : List : [1 : "John", 2 : "Tom"] Output: 2Approach 1: using Iteration Create a size variable of integer data type and initialize it with 0.Start iterating through the LinkedHashMap and increment the size variable at each iteration.After completion of the iteration, print size variable.Below is the implementation of the above approach: Java // Java Program to find the size of LinkedHashMap import java.util.*; public class LinkedHashMapSizeExample { public static void main(String[] args) { // LinkedHashMap Initialization LinkedHashMap<Integer, String> lhMapColors = new LinkedHashMap<Integer, String>(); lhMapColors.put(1, "red"); lhMapColors.put(2, "white"); lhMapColors.put(3, "blue"); // Create of size variable and initialize with 0 int size = 0; for (Map.Entry mapElement : lhMapColors.entrySet()) { size++; } System.out.println("Size of LinkedHashMap is " + size); } } OutputSize of LinkedHashMap is 3Approach 2: Using size() Method Syntax: List.size() Return Type: IntegerCreate a size variable of integer data type and initialize it with the size() method.Print size variable.Below is the implementation of the above approach: Java // Java Program to find the size of LinkedHashMap import java.util.LinkedHashMap; public class LinkedHashMapSizeExample { public static void main(String[] args) { // Initialize LinkedHashMap LinkedHashMap<Integer, String> lhMapColors = new LinkedHashMap<Integer, String>(); // Add elements lhMapColors.put(1, "red"); lhMapColors.put(2, "white"); lhMapColors.put(3, "blue"); // Create size variable and initialize // it with size() method int size = lhMapColors.size(); System.out.println("Size of LinkedHashMap is " + size); } } OutputSize of LinkedHashMap is 3 Comment More infoAdvertise with us Next Article How to Check the LinkedHashMap Size in Java? P patelnagendra1 Follow Improve Article Tags : Java Java Programs Java-LinkedHashMap Practice Tags : Java Similar Reads How to Convert LinkedHashMap to List in Java? LinkedHashMap is predefined class in Java which is similar to HashMap, contains key and its respective value unlike HashMap, in LinkedHashMap insertion order is preserved. We to convert LinkedHashMap to ArrayList. A Map store data in pair of Key and Value while converting a LinkedHashMAp to ArrayLis 2 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 Check if LinkedHashMap is Empty in Java? 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 2 min read How to Print all Keys of the LinkedHashMap in Java? LinkedHashMap is a predefined class in Java that is similar to HashMap, contains a key and its respective value. Unlike HashMap, In LinkedHashMap insertion order is preserved. The task is to print all the Keys present in our LinkedHashMap in java. We have to iterate through each Key in our LinkedHas 2 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