fork download
  1. package org.JavaIncloud.java;
  2.  
  3. import java.util.HashMap;
  4. import java.util.Map;
  5. import java.util.logging.Logger;
  6.  
  7. public class MapShowCase
  8. {
  9. public static final Logger log = Logger.getLogger(MemoryManagement.class.getName());
  10.  
  11. public void iterateMapFromJavaInCloud(HashMap<String, Integer> passAMap)
  12. {
  13. Map<String, Integer> bodyMap = passAMap;
  14. /*
  15. * N.B- You can use following method with for loop, for each loop,
  16. * iterator or Enumeration, you can choose any one according to your convenient.
  17. */
  18. //Iterate over Key(It includes Way-1 and Way-2)
  19. //Way-1
  20. for (String babyName : bodyMap.keySet())
  21. {
  22. log.info("Baby Name(Key)>> "+babyName);
  23. log.info("Baby Age(Value)>>"+bodyMap.get(babyName));
  24. }
  25. //performance wise more efficient than Way-1
  26. //Way-2
  27. for (Map.Entry<String, Integer> babyEntry : bodyMap.entrySet())
  28. {
  29. log.info("Baby Name(Key)>> "+babyEntry.getKey());
  30. log.info("Baby Age(Value)>>"+babyEntry.getValue());
  31. }
  32. //Iterate over value(It includes Way-3)
  33. //Way-3
  34. for (Integer babyAge : bodyMap.values())
  35. {
  36. log.info("Baby Age(Value)>>" + babyAge);
  37. }
  38. }
  39. }
  40.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:7: error: class MapShowCase is public, should be declared in a file named MapShowCase.java
public class MapShowCase 
       ^
Main.java:9: error: cannot find symbol
	public static final Logger	log	= Logger.getLogger(MemoryManagement.class.getName());
	                          	   	                   ^
  symbol:   class MemoryManagement
  location: class MapShowCase
2 errors
stdout
Standard output is empty