Skip to content

Instantly share code, notes, and snippets.

@fijiaaron
Last active October 23, 2017 15:45
Show Gist options
  • Save fijiaaron/0d721608d5bef6d3b3749dce18e1a375 to your computer and use it in GitHub Desktop.
Save fijiaaron/0d721608d5bef6d3b3749dce18e1a375 to your computer and use it in GitHub Desktop.
ways to map a map in java
import java.util.Map;
public class MapMap
{
Map<String, String> map;
public static void map(Object key, Object value)
{
System.out.println(key + ":" + value);
}
public void mapmap()
{
/* loop */
for (Map.Entry entry: map.entrySet())
{
map(entry.getKey(), entry.getValue());
}
/* lambda expression */
map.forEach((key,value) -> {
map(key, value);
});
/* simplified lambda */
map.forEach((key,value) -> map(key, value));
/* method reference */
map.forEach(MapMap::map);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment