<div dir="ltr" style="text-align: justify;" trbidi="on">This class extends <b>HashMap </b>and maintains a linked list of the entries in the map, in the order in which they were inserted.</p>
<p> This allows insertion-order iteration over the map. That is, when iterating a <b>LinkedHashMap</b>, the elements will be returned in the order in which they were inserted.</p>
<p> You can also create a <b>LinkedHashMap </b>that returns its elements in the order in which they were last accessed.</p>
<p> The <b>LinkedHashMap </b>class supports five constructors. The first form constructs a default <b>LinkedHashMap</b>:</p>
<pre class="highlight" name="code">LinkedHashMap( ) 
</pre>
<p>The second form initializes the <b>LinkedHashMap </b>with the elements from m:</p>
<pre class="highlight" name="code">LinkedHashMap(Map m) 
</pre>
<p>The third form initializes the capacity:</p>
<pre class="highlight" name="code">LinkedHashMap(int capacity) 
</pre>
<div align='center' id="ads-id"></div>
<p>The fourth form initializes both capacity and fill ratio. The meaning of capacity and fill ratio are the same as for <b>HashMap</b>:</p>
<pre class="highlight" name="code">LinkedHashMap(int capacity, float fillRatio) 
</pre>
<p>The last form allows you to specify whether the elements will be stored in the linked list by insertion order, or by order of last access. If Order is true, then access order is used. If Order is false, then insertion order is used.</p>
<pre class="highlight" name="code">LinkedHashMap(int capacity, float fillRatio, boolean Order) 
</pre>
<ol>
<li>A <b>LinkedHashMap </b>contains values based on the key. It implements the Map interface and extends <b>HashMap </b>class.</li>
<li>It contains only unique elements.</li>
<li>It may have one null key and multiple null values.</li>
<li>It is same as <b>HashMap </b>instead maintains insertion order.</li>
</ol>
<p><b>Hierarchy of <i>LinkedHashMap </i>class:</b></p>
<div class="separator" style="clear: both; text-align: center;"><img border="0" src="https://dineshonjava.com/wp-content/uploads/2013/06/linkedhashmap.jpg"/></div>
<div style="background-color: white; font-family: Helvetica,Arial,sans-serif; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; margin: 0.8em 0px 1em; padding: 0px; text-align: justify; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;">Apart from the methods inherited from its parent classes, <i><b>LinkedHashMap </b></i>defines following methods:</div>
<table class="src" style="-webkit-text-stroke-width: 0px; background-color: #f7f7f7; border-collapse: collapse; border: 1px solid rgb(214, 214, 214); color: black; font-family: Helvetica, Arial, sans-serif; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; margin: 8px 0px; orphans: auto; padding: 0px; text-align: start; text-indent: 0px; text-transform: none; vertical-align: top; white-space: normal; widows: auto; width: 560px; word-spacing: 0px;">
<tbody style="margin: 0px; padding: 0px;">
<tr style="margin: 0px; padding: 0px;">
<th style="background-color: #eeeeee; border-collapse: collapse; border: 1px solid rgb(214, 214, 214); margin: 0px; padding: 5px; text-align: left;">SN</th>
<th style="background-color: #eeeeee; border-collapse: collapse; border: 1px solid rgb(214, 214, 214); margin: 0px; padding: 5px; text-align: left;">Methods with Description</th>
</tr>
<tr style="margin: 0px; padding: 0px;">
<td style="border-collapse: collapse; border: 1px solid rgb(214, 214, 214); margin: 0px; padding: 5px;">1</td>
<td style="border-collapse: collapse; border: 1px solid rgb(214, 214, 214); margin: 0px; padding: 5px;"><b style="margin: 0px; padding: 0px;">void clear() ;</b><br />
Removes all mappings from this map.</td>
</tr>
<tr style="margin: 0px; padding: 0px;">
<td style="border-collapse: collapse; border: 1px solid rgb(214, 214, 214); margin: 0px; padding: 5px;">2</td>
<td style="border-collapse: collapse; border: 1px solid rgb(214, 214, 214); margin: 0px; padding: 5px;"><b style="margin: 0px; padding: 0px;">boolean containsKey(Object key) ;</b><br />
Returns true if this map maps one or more keys to the specified value.</td>
</tr>
<tr style="margin: 0px; padding: 0px;">
<td style="border-collapse: collapse; border: 1px solid rgb(214, 214, 214); margin: 0px; padding: 5px;">3</td>
<td style="border-collapse: collapse; border: 1px solid rgb(214, 214, 214); margin: 0px; padding: 5px;"><b style="margin: 0px; padding: 0px;">Object get(Object key) ;</b><br />
Returns the value to which this map maps the specified key.</td>
</tr>
<tr style="margin: 0px; padding: 0px;">
<td style="border-collapse: collapse; border: 1px solid rgb(214, 214, 214); margin: 0px; padding: 5px;">4</td>
<td style="border-collapse: collapse; border: 1px solid rgb(214, 214, 214); margin: 0px; padding: 5px;"><b style="margin: 0px; padding: 0px;">protected boolean removeEldestEntry(Map.Entry eldest) ;</b><br />
Returns true if this map should remove its eldest entry.</td>
</tr>
</tbody>
</table>
<p>
<b>Example of <i>LinkedHashMap </i>class:</b></p>
<pre class="highlight" name="code">import java.util.*; 
class Simple{ 
 public static void main(String args[]){ 
 
 LinkedHashMap hm=new LinkedHashMap(); 
 
 hm.put(100,"Dinesh"); 
 hm.put(101,"Sweety"); 
 hm.put(102,"Nimmo"); 
 
 Set set=hm.entrySet(); 
 Iterator itr=set.iterator(); 
 
 while(itr.hasNext()){ 
 Map.Entry m=(Map.Entry)itr.next(); 
 System.out.println(m.getKey()+" "+m.getValue()); 
 } 
 } 
} 
</pre>
<p></p>
<div style="background-color: #ff99cc;"><b>Output:</b><br />
100 Dinesh<br />
101 Sweety<br />
103 Nimmo</div>
<div style="background-color: #f2f9fc; border-radius: 3px; border: 1px solid #c9e6f2; line-height: 1.45; padding: 16px;">
<b>Java Collections Tutorial</b></p>
<ol style="text-align: left;">
<li><b><a href="https://dineshonjava.com/arraylist-class-in-java-collection/">ArrayList class</a></b></li>
<li><b><a href="https://dineshonjava.com/linkedlist-class-in-collection/">LinkedList class</a></b></li>
<li><b><a href="https://dineshonjava.com/listiterator-interface-in-collection/">ListIterator interface</a></b></li>
<li><b><a href="https://dineshonjava.com/hashset-class-in-collection/">HashSet class</a></b></li>
<li><b><a href="https://dineshonjava.com/linkedhashset-class-in-collection/">LinkedHashSet class</a></b></li>
<li><b><a href="https://dineshonjava.com/treeset-classin-collection/">TreeSet class</a></b></li>
<li><b><a href="https://dineshonjava.com/difference-between-hashset-and-treeset/">Difference between TreeSet &; HashSet</a></b></li>
<li><b><a href="https://dineshonjava.com/map-interface-in-collection/">Map interface</a></b></li>
<li><b><a href="https://dineshonjava.com/hashmap-class-in-collection-framework/">HashMap class</a></b></li>
<li><b><a href="https://dineshonjava.com/how-does-java-hashmap-work-internally/">How does work HashMap?</a> </b></li>
<li><b><a href="https://dineshonjava.com/difference-between-treemap-vs-hashmap/">Difference between TreeMap vs HashMap</a></b></li>
<li><b><a href="https://dineshonjava.com/treemap-class-in-collection-framework/">TreeMap class</a></b></li>
<li><b><a href="https://dineshonjava.com/hashtable-class-in-collection-framework/">Hashtable class</a></b></li>
<li><b><a href="https://dineshonjava.com/difference-between-hashmap-and/">Difference between HashMap and HashTable in Java</a></b></li>
<li><b><a href="https://dineshonjava.com/sorting-in-collection-framework/">Sorting</a></b></li>
<li><b><a href="https://dineshonjava.com/java-comparable-and-comparator/">Comparable interface</a></b></li>
</ol>
</div>
<p></p>
<div style="background-color: pink; border-width: thin; text-align: center;"><b><;<;<a href="https://dineshonjava.com/how-does-java-hashmap-work-internally/">Previous</a> <;<; ; ; || <a href="https://dineshonjava.com/core-java-baby-step-to-be-best-java-ian/">Index </a>||  ; >;>;<a href="https://dineshonjava.com/treemap-class-in-collection-framework/">Next</a> >;>;</b></div>
</div>
<div class="wp-post-navigation"> 
									 <div class="wp-post-navigation-pre"> 
									 <a href="https://dineshonjava.com/how-does-java-hashmap-work-internally/">Previous</a> 
									 </div> 
									 <div class="wp-post-navigation-next"> 
									 <a href="https://dineshonjava.com/treemap-class-in-collection-framework/">Next</a> 
									 </div> 
									</div>
<script type="text/javascript">
jQuery(document).ready(function($) {
 $.post('https://dineshonjava.com/wp-admin/admin-ajax.php', {action: 'mts_view_count', id: '412'});
});
</script>
Strategy Design Patterns We can easily create a strategy design pattern using lambda. To implement…
Decorator Pattern A decorator pattern allows a user to add new functionality to an existing…
Delegating pattern In software engineering, the delegation pattern is an object-oriented design pattern that allows…
Technology has emerged a lot in the last decade, and now we have artificial intelligence;…
Managing a database is becoming increasingly complex now due to the vast amount of data…
Overview In this article, we will explore Spring Scheduler how we could use it by…