Skip to content

Instantly share code, notes, and snippets.

@shoon
Created March 27, 2015 20:04
Show Gist options
  • Save shoon/df909f1e3fcb35754dc9 to your computer and use it in GitHub Desktop.
Save shoon/df909f1e3fcb35754dc9 to your computer and use it in GitHub Desktop.
Java Map replaceAll Example
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));
}
}
@shoon
Copy link
Author

shoon commented Mar 27, 2015

Good demo of how simple lamdas in Java collections can be

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment