1. package com.instaceofjava; 
  2.  
  3. import java.util.HashMap;
  4. import java.util.Iterator;
  5. import java.util.Map;
  6. import java.util.Map.Entry;
  7.  
  8. public class Mapiterator {
  9.  
  10. public static void main(String[] args) {
  11.  
  12. HashMap map=new HashMap();
  13.  
  14. map.put(1, "indhu");
  15. map.put("d", "sindhu");
  16. map.put("3", "swathi");
  17.  
  18. if(!map.isEmpty()){
  19.  
  20. Iterator it=map.entrySet().iterator();
  21.  
  22. while(it.hasNext()){
  23.  
  24. Map.Entry obj=(Entry) it.next();
  25. System.out.println(obj.getValue());
  26.  
  27. }
  28.  
  29. }
  30.  
  31. }
  32.  
  33. }


Output:

  1. swathi 
  2. indhu
  3. sindhu

Instance Of Java

We are here to help you learn! Feel free to leave your comments and suggestions in the comment section. If you have any doubts, use the search box on the right to find answers. Thank you! 😊
«
Next
Newer Post
»
Previous
Older Post

No comments

Leave a Reply

Select Menu