Last active
October 23, 2017 15:45
-
-
Save fijiaaron/0d721608d5bef6d3b3749dce18e1a375 to your computer and use it in GitHub Desktop.
ways to map a map in java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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