<div dir="ltr" style="text-align: justify;" trbidi="on">
<ol>
<li><b>HashMap </b>class extends <b>AbstractMap </b>and implements <b>Map </b>interface.</li>
<li>It uses a <b>hashtable </b>to store the map. This allows the execution time of <b>get() and put() </b>to remain same.</li>
<li><b>HashMap </b>has four constructor.</li>
<pre class="highlight" name="code">HashMap() 
HashMap(Map<; ? extends k, ? extends V>; m) 
HashMap(int capacity) 
HashMap(int capacity, float fillratio) 
</pre>
<li><b>HashMap </b>does not maintain order of its element.</li>
</ol>
<p><b>Hierarchy of <i>HashMap </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/hashmap.jpg"/></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;">Object clone() ;</b><br />
Returns a shallow copy of this HashMap instance: the keys and values themselves are not cloned.</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;">boolean containsKey(Object key) ;</b><br />
Returns true if this map contains a mapping for 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;">boolean containsValue(Object value) ;</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;">5</td>
<td style="border-collapse: collapse; border: 1px solid rgb(214, 214, 214); margin: 0px; padding: 5px;"><b style="margin: 0px; padding: 0px;">Set entrySet() ;</b><br />
Returns a collection view of the mappings contained in 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;">6</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 the specified key is mapped in this identity hash map, or null if the map contains no mapping for this 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;">7</td>
<td style="border-collapse: collapse; border: 1px solid rgb(214, 214, 214); margin: 0px; padding: 5px;"><b style="margin: 0px; padding: 0px;">boolean isEmpty()</b><br />
Returns true if this map contains no key-value mappings.</td>
</tr>
<tr style="margin: 0px; padding: 0px;">
<td style="border-collapse: collapse; border: 1px solid rgb(214, 214, 214); margin: 0px; padding: 5px;">8</td>
<td style="border-collapse: collapse; border: 1px solid rgb(214, 214, 214); margin: 0px; padding: 5px;"><b style="margin: 0px; padding: 0px;">Set keySet() ;</b><br />
Returns a set view of the keys contained in 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;">9</td>
<td style="border-collapse: collapse; border: 1px solid rgb(214, 214, 214); margin: 0px; padding: 5px;"><b style="margin: 0px; padding: 0px;">Object put(Object key, Object value)</b><br />
Associates the specified value with the specified key in 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;">10</td>
<td style="border-collapse: collapse; border: 1px solid rgb(214, 214, 214); margin: 0px; padding: 5px;"><b style="margin: 0px; padding: 0px;">putAll(Map m) ;</b><br />
Copies all of the mappings from the specified map to this map These mappings will replace any mappings that this map had for any of the keys currently in the specified 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;">11</td>
<td style="border-collapse: collapse; border: 1px solid rgb(214, 214, 214); margin: 0px; padding: 5px;"><b style="margin: 0px; padding: 0px;">Object remove(Object key) ;</b><br />
Removes the mapping for this key from this map if present.</td>
</tr>
<tr style="margin: 0px; padding: 0px;">
<td style="border-collapse: collapse; border: 1px solid rgb(214, 214, 214); margin: 0px; padding: 5px;">12</td>
<td style="border-collapse: collapse; border: 1px solid rgb(214, 214, 214); margin: 0px; padding: 5px;"><b style="margin: 0px; padding: 0px;">int size() ;</b><br />
Returns the number of key-value mappings in 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;">13</td>
<td style="border-collapse: collapse; border: 1px solid rgb(214, 214, 214); margin: 0px; padding: 5px;"><b style="margin: 0px; padding: 0px;">Collection values() ;</b><br />
Returns a collection view of the values contained in this map.</td>
</tr>
</tbody>
</table>
<div align='center' id="ads-id"></div>
<p><b>Example of <i>HashMap </i>class:</b></p>
<pre class="highlight" name="code">import java.util.*; 
class Simple{ 
 public static void main(String args[]){ 
 
 HashMap hm=new HashMap(); 
 
 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>
<b><br />
</b> </p>
<div style="background-color: #ff99cc;"><b>Output:</b><br />
102 Dinesh<br />
100 Sweety<br />
101 Nimmo</div>
<p></p>
<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/linkedhashmap-class-in-collection/">LinkedHashMap class</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>
<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/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/linkedhashmap-class-in-collection/">LinkedHashMap class</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/map-interface-in-collection/">Previous</a> <;<; ; ; || <a href="https://dineshonjava.com/core-java-baby-step-to-be-best-java-ian/">Index </a>||  ; >;>;<a href="https://dineshonjava.com/how-does-java-hashmap-work-internally/">Next</a> >;>;</b></div>
</div>
<div class="wp-post-navigation"> 
									 <div class="wp-post-navigation-pre"> 
									 <a href="https://dineshonjava.com/map-interface-in-collection/">Previous</a> 
									 </div> 
									 <div class="wp-post-navigation-next"> 
									 <a href="https://dineshonjava.com/how-does-java-hashmap-work-internally/">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: '414'});
});
</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…