Menu Bar

Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Friday, 7 October 2016

What is LinkedHashMap In Java ?

This blog is all about to learn Core Java Interview Programs and Coding tricks to polish your Java Knowledge. If you like the content of this blog please share this with your friends.

Previously we have discussed about
What is ConcurrentHashMap In Java ?
Here, we learn What is LinkedHashMap In Java.But before starting we must know what is Map Interface In Java.?
Class LinkedHashMap<K,V>

Type Parameters :-
K - the type of keys maintained by this map
V - the type of mapped values

All Implemented Interfaces :-

Declaration of LinkedHashMap:
public class LinkedHashMap<K,V>
implements Map<K,V>

LinkedHashMap is a implementation class of Map Interface.It belongs to java.util.*; package.
LinkedHashMap implementation differs from HashMap in that it maintains a doubly-linked list running through all of its entries. 
LinkedHashMap Maintains the Insertion order of elements in which keys were inserted into the map.
A linked hash map has two parameters that affect its performance: initial capacity and load factor.
They are defined precisely as for HashMapLinkedHashMap implementation is not synchronized.
If multiple threads access a LinkedHashMap concurrently, and at least one of the threads modifies the map means that thread can adds or deletes one or more mappings.To prevent this we can synchronized the LinkedHashMap using 

Map m = Collections.synchronizedMap(new LinkedHashMap(...));

LinkedHashMap is an example of fail-fast.And This class is a member of the Java Collections Framework.

Constructor and Description :-

LinkedHashMap()
Constructs an empty insertion-ordered LinkedHashMap instance with the default initial capacity (16) and load factor (0.75).

LinkedHashMap(int initialCapacity)
Constructs an empty insertion-ordered LinkedHashMap instance with the specified initial capacity and a default load factor (0.75).

LinkedHashMap(int initialCapacity, float loadFactor)
Constructs an empty insertion-ordered LinkedHashMap instance with the specified initial capacity and load factor.

LinkedHashMap(int initialCapacity, float loadFactor, boolean accessOrder)
Constructs an empty LinkedHashMap instance with the specified initial capacity, load factor and ordering mode.

LinkedHashMap(Map<? extends K,? extends V> m)
Constructs an insertion-ordered LinkedHashMap instance with the same mappings as the specified map.
Share this Blog with yours Friends !!

No comments:

Post a Comment