Wednesday 16 April 2014

Map.Entry : hashCode : HashCode for the Map Entry

int hashCode()
return the hash code value for this map entry.

import java.util.*;
class MapEntrySetHashCode{
  public static void main(String args[]){
         Map<Integer, String> myMap = new HashMap<> ();
  
  /* Put the data to Map */
  myMap.put(1, "First");
  myMap.put(2, "Second");
  myMap.put(3, "Third");
  myMap.put(4, "Fourth");
  
  int i = 1;
  
  for(Map.Entry<Integer, String> entry1 : myMap.entrySet()){
  System.out.print("\nHash Code Of Entry ");
  System.out.println(entry1 + " is " + entry1.hashCode());
  }
  }
}

Output
Hash Code Of Entry 1=First is 67887761

Hash Code Of Entry 2=Second is -1822412650

Hash Code Of Entry 3=Third is 80778564

Hash Code Of Entry 4=Fourth is 2110150206




Prevoius                                                 Next                                                 Home

No comments:

Post a Comment