Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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