Tuesday 15 April 2014

Map.Entry : getKey : get the key corresponding to this entry

K getKey()
Return the key corresponding to this entry.

import java.util.*;

class MapEntryGetKey{
  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");
  
  System.out.println("Keys in the Map are");
  for(Map.Entry<Integer, String> entry : myMap.entrySet()){
  System.out.println(entry.getKey());
  }
  }
}


Output
Keys in the Map are
1
2
3
4



Prevoius                                                 Next                                                 Home

No comments:

Post a Comment