hashmap - Printing a java map Map<String, Object> - How? -
this question has answer here:
how print information map has object value?
i have created following map:
map<string, object> objectset = new hashmap<>();
the object has own class own instance variables
i have populated above map data.
i have created printmap
method, can seem print keys of map
how map print <object>
values using each loop?
so far, i've got:
for (string keys : objectset.keyset()) { system.out.println(keys); }
the above prints out keys. want able print out object variables too.
i'm sure there's nice library sort of thing you... stick approach you're going with, map#entryset
gives combined object
key
and value
. like:
for (map.entry<string, object> entry : map.entryset()) { system.out.println(entry.getkey() + ":" + entry.getvalue().tostring()); }
will you're after.
if you're using java 8, there's new streaming approach.
map.foreach((key, value) -> system.out.println(key + ":" + value));
Comments
Post a Comment