A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/java/java-program-to-print-linkedhashmap-values/ below:

Java Program to Print LinkedHashMap Values

Java Program to Print LinkedHashMap Values

Last Updated : 23 Jul, 2025

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. 

Example: 

Input:

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

Algorithm:

Example:

Java
// Java program to print all the values
// of the LinkedHashMap

import java.util.*;
import java.io.*;

class GFG {
    public static void main (String[] args) {
      
      LinkedHashMap<Integer,Integer> LHM = new LinkedHashMap<>();
      
      LHM.put(2,5);
      LHM.put(4,3);
      LHM.put(1,10);
      LHM.put(3,12);
      LHM.put(5,6);
      
      // using .entrySet() which gives us the 
      // list of mappings of the Map
      for(Map.Entry<Integer,Integer>it:LHM.entrySet())
          System.out.print(it.getValue()+", ");
    }
}

Time complexity: O(n). 



RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4