![]() |
LinkedHashMap in Java maintains the order of elements based on which they were inserted. It achieves this by using a doubly-linked list internally to maintain the order of elements along with a hash table for retrieval. In this article, we are going to discuss how LinkedHashMap maintains insertion order. Example of LinkedHashMap to maintain insertion order:
Syntax of LinkedHashMap:public class LinkedHashMap<K,V> extends HashMap<K,V> implements Map<K,V> Where,
Program to maintain insertion order in LinkedHashMap in JavaBelow is the implementation of LinkedHashMap to maintain insertion order. Java
Output
LinkedHashMap elements in insertion order: One: 1 Two: 2 Three: 3 LinkedHashMap elements after adding more elements: One: 1 Two: 2 Three: 3 Four: 4 Five: 5 Explanation of the Program:
|
Reffered: https://www.geeksforgeeks.org
Java |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 14 |