Created
March 27, 2015 20:04
-
-
Save shoon/df909f1e3fcb35754dc9 to your computer and use it in GitHub Desktop.
Java Map replaceAll Example
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.HashMap; | |
import java.util.Map; | |
public class MapLamdaTest { | |
public static void main(String[] args) { | |
Map<String, Boolean> booleanMap = new HashMap<String, Boolean>(2); | |
booleanMap.put("A", Boolean.TRUE); | |
booleanMap.put("B", Boolean.FALSE); | |
booleanMap.put("C", Boolean.TRUE); | |
System.out.println("Hashmap created, here are the values"); | |
// Print out the map | |
booleanMap.forEach((k, v) -> System.out.println(k + " " + v)); | |
booleanMap.replaceAll((k, v) -> Boolean.FALSE); | |
System.out.println("Hashmap replaceAll, here are the values"); | |
long startTime = System.currentTimeMillis(); | |
// Print out the modified values | |
booleanMap.forEach((k, v) -> System.out.println(k + " " + v)); | |
long stopTime = System.currentTimeMillis(); | |
System.out.println("Replace took time " + (stopTime-startTime)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Good demo of how simple lamdas in Java collections can be