java - Retrive Nested Hashmap data from yaml file -
i have following yaml data
networklayerconfig: eventmap: !!map !!int 100 : !!int 1 : idling !!int 2 : accepting i use yamlbean read data following class
class networklayerconfig { private hashmap<integer, map<integer, string>> eventmap; } i trying access every key , associated value pair.
if try access these data when declared in java class like
myhashmap = new hashmap<integer, map<integer, string>>(); myhashmap.put(100, new hashmap<integer, string>()); myhashmap.get(100).put(1, "idling"); myhashmap.get(100).put(2, "accepting"); using following code
for (map.entry<integer, string> onemap : myhashmap.get(100).entryset()) { system.out.println(onemap.getkey()); system.out.println(onemap.getvalue()); } since have read value 100 yaml file (i.e, during runtime) don't know how access every data.
i solved problem access every value in hashmap
iterator<?> iterator = myparenthashmap.entryset().iterator(); while (iterator.hasnext()) { entry myentry = (entry) iterator.next(); system.out.println(myentry.getkey() + " : "); hashmap<integer, string> childhashmaps = ((hashmap<integer, string>) myentry.getvalue()); system.out.println("{"); (map.entry<integer, string> childhashmap : childhashmaps.entryset()) { system.out.print(childhashmap.getkey() + " : "); system.out.println(childhashmap.getvalue()); } system.out.println("}"); }
Comments
Post a Comment