I'm sure there's some nice library that does this sort of thing already for you... But to just stick with the approach you're already going with, Map#entrySet
gives you a combined Object
with the key
and the value
. So something like:
for (Map.Entry<String, Object> entry : map.entrySet()) {
System.out.println(entry.getKey() + ":" + entry.getValue().toString());
}
will do what you're after.
If you're using java 8, there's also the new streaming approach.
map.forEach((key, value) -> System.out.println(key + ":" + value));
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…