Sunday 28 October 2018

hashmap - Printing a java map Map - How?

How to I print information from a map that has the object as the value?




I have created the following map:



Map objectSet = new HashMap<>();


The object has its own class with its own instance variables



I have already populated the above map with data.




I have created a printMap method, but I can only seem to print the Keys of the map



How to do I get the map to print the values using a for each loop?



So far, I've got:



for (String keys : objectSet.keySet())
{
System.out.println(keys);
}



The above prints out the keys. I want to be able to print out the object variables too.

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...