Java HashMap

New Picture.png

  1. HashMap is an in-built class which inherits AbstractMap class and implements Map interface.
  2. HashMap maintains key and value pairs and often denoted as HashMap or HashMap.
  3. A HashMap contains values based on the key.
  4. It contains only unique elements.
  5. It may have one null key and multiple null values.
  6. It maintains no order, that means it is not an ordered collection which means it does not return the keys and values in the same order in which they have been inserted into the HashMap.

HashMap class declaration

Let's see the declaration for java.util.HashMap class. public class HashMap extends AbstractMap implements Map, Cloneable, Serializable here, in this declaration :

  1. K: It is the type of keys maintained by this map.
  2. V: It is the type of mapped values.

JAVA HashMap Example:

HashMapDemo.java

  import java.util.*;
   class HashMapDemo
     {
      public static void main(String args[])         {
          HashMap<Integer,String> hm=new HashMap<Integer,String>();
          hm.put(1000,"Akshaya");
          hm.put(1001,"Santosh");
          hm.put(1002,"Rakesh");
          for(Map.Entry m:hm.entrySet())
            {
              System.out.println(m.getKey()+" "+m.getValue());
            }
        }
    }

Output

hash_output

Our Services:

Java Training | Python Training | Machine Learning with Python Training | Deep Learning with Python Training | Data Science with Python Training | Projects

SILAN Technology, BBSR
Call to: 0674-2361252

Comment