package org.JavaIncloud.java ;
import java.util.HashMap ;
import java.util.Map ;
import java.util.logging.Logger ;
public class MapShowCase
{
public static final Logger log = Logger.getLogger ( MemoryManagement.class .getName ( ) ) ;
public void iterateMapFromJavaInCloud
( HashMap
< String , Integer
> passAMap
) {
Map
< String , Integer
> bodyMap
= passAMap
; /*
* N.B- You can use following method with for loop, for each loop,
* iterator or Enumeration, you can choose any one according to your convenient.
*/
//Iterate over Key(It includes Way-1 and Way-2)
//Way-1
for ( String babyName
: bodyMap.
keySet ( ) ) {
log.info ( "Baby Name(Key)>> " + babyName) ;
log.info ( "Baby Age(Value)>>" + bodyMap.get ( babyName) ) ;
}
//performance wise more efficient than Way-1
//Way-2
for ( Map .
Entry < String , Integer
> babyEntry
: bodyMap.
entrySet ( ) ) {
log.info ( "Baby Name(Key)>> " + babyEntry.getKey ( ) ) ;
log.info ( "Baby Age(Value)>>" + babyEntry.getValue ( ) ) ;
}
//Iterate over value(It includes Way-3)
//Way-3
for ( Integer babyAge
: bodyMap.
values ( ) ) {
log.info ( "Baby Age(Value)>>" + babyAge) ;
}
}
}
cGFja2FnZSBvcmcuSmF2YUluY2xvdWQuamF2YTsKCmltcG9ydCBqYXZhLnV0aWwuSGFzaE1hcDsKaW1wb3J0IGphdmEudXRpbC5NYXA7CmltcG9ydCBqYXZhLnV0aWwubG9nZ2luZy5Mb2dnZXI7CgpwdWJsaWMgY2xhc3MgTWFwU2hvd0Nhc2UgCnsKCXB1YmxpYyBzdGF0aWMgZmluYWwgTG9nZ2VyCWxvZwk9IExvZ2dlci5nZXRMb2dnZXIoTWVtb3J5TWFuYWdlbWVudC5jbGFzcy5nZXROYW1lKCkpOwoJCglwdWJsaWMgdm9pZCBpdGVyYXRlTWFwRnJvbUphdmFJbkNsb3VkKEhhc2hNYXA8U3RyaW5nLCBJbnRlZ2VyPiBwYXNzQU1hcCkKCXsKCQlNYXA8U3RyaW5nLCBJbnRlZ2VyPiBib2R5TWFwID0gcGFzc0FNYXA7CgkJLyoK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JhYnkgQWdlKFZhbHVlKT4+IiArIGJhYnlBZ2UpOwogICAgICAJfQoJfQp9Cg==
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