Skip to content
Related Articles

Related Articles

Java Program to Print LinkedHashMap Values
  • Last Updated : 07 Jan, 2021

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. We need to print the value of the hash map which is linked with its key. We have to iterate through each Key present in our LinkedHashMap and print its respective value by using a for loop. 



Key- 2 : Value-5
Key- 4 : Value-3
Key- 1 : Value-10
Key- 3 : Value-12
Key- 5 : Value-6

Output: 5, 3, 10, 12, 6


  • Use For-each loop to iterate through LinkedHashMap.
  • Using entrySet() method which gives the set structure of all the mappings of the map for iterating through the whole map. For each iteration print its respective value



// Java program to print all the values
// of the LinkedHashMap
import java.util.*;
class GFG {
    public static void main (String[] args) {
      LinkedHashMap<Integer,Integer> LHM = new LinkedHashMap<>();
      // using .entrySet() which gives us the 
      // list of mappings of the Map
          System.out.print(it.getValue()+", ");
5, 3, 10, 12, 6,

Time complexity: O(n). 

Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.

My Personal Notes arrow_drop_up
Recommended Articles
Page :