Tuesday, 3 June 2014

HashMap()

HashMap()
Constructs an empty HashMap with the default initial capacity 16 and the default load factor 0.75. 

Example
import java.util.*;

class HashMapConstructor1{
  public static void main(String args[]){
    Map<Integer, String> myMap = new HashMap<> ();
  
  /* Adding Data to myMap */
  myMap.put(1, "First");
  myMap.put(2, "Second");
  myMap.put(3, "Third");
  myMap.put(4, "Fourth");
  
  System.out.println("Elements in myMap are");
  System.out.println(myMap);
  }
}

Output
Elements in myMap are
{1=First, 2=Second, 3=Third, 4=Fourth}





Prevoius                                                 Next                                                 Home

No comments:

Post a Comment