Skip to content

Instantly share code, notes, and snippets.

@webdeveloper987
Created July 18, 2013 23:27
Show Gist options
  • Save webdeveloper987/6033953 to your computer and use it in GitHub Desktop.
Save webdeveloper987/6033953 to your computer and use it in GitHub Desktop.
Java - iterate over HashMap
Map<String, Object> map = ...;
for (String key : map.keySet())
{
// ...
}
//If you only need the values, use values():
for (Object value : map.values())
{
// ...
}
//Finally, if you want both the key and value, use entrySet():
for (Map.Entry<String, Object> entry : map.entrySet()) {
String key = entry.getKey();
Object value = entry.getValue();
// ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment