Last Updated : 23 Jul, 2025
LinkedHashMap is a Hash table and linked list implementation of the Map interface. In LinkedHashMap order of key-value pair depends on the order in which keys were inserted into the map. Insertion order does not affect if a key is reinserted into the map.
Example:
Input: Key: 1 Value : 1221 Key: 2 Value : 2112 Output: Keys : [1,2] Values : [1221,2112] Key-Value pairs : [1=1221, 2=2112]
Methods Use:
Approach:
Below is the implementation of the above approach:
Java
// Java Program to add key-value
// pairs to LinkedHashMap
import java.util.*;
public class Main {
public static void main(String[] args)
{
// create an instance of LinkedHashMap
LinkedHashMap<Integer, Integer> map
= new LinkedHashMap<Integer, Integer>();
int num, key, val;
num = 2;
for (int i = 0; i < num; i++) {
// Taking inputs from user
key = i + 1;
val = key * 10;
// Add mappings using put method
map.put(key, val);
}
// Displaying key
System.out.println("Keys: " + map.keySet());
// Displaying value
System.out.println("Values: " + map.values());
// Displaying key-value pair
System.out.println("Key-Value pairs: "
+ map.entrySet());
}
}
Keys: [1, 2] Values: [10, 20] Key-Value pairs: [1=10, 2=20]
Time Complexity: O(1)
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