Thursday, January 31, 2019

Lambda example

package com.concretepage;
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.valueOf("true"));booleanMap.put("B", Boolean.FALSE);booleanMap.put("C", Boolean.TRUE);
        booleanMap.put("D", true);booleanMap.put("E", Boolean.valueOf("true"));booleanMap.put("F", Boolean.valueOf("false"));
        System.out.println("Hashmap created, here are the values");
        // Print out the map
        booleanMap.forEach((m, l) -> System.out.println(m + " " + l));
        booleanMap.replaceAll((m,l) -> Boolean.FALSE);
        System.out.println("Hashmap replaceAll, here are the values");
        long startTime = System.currentTimeMillis();
        // Print out the modified values
        booleanMap.forEach((m,l) -> System.out.println(m + " " + l));
        long stopTime = System.currentTimeMillis();
        System.out.println("Replace took time " + (stopTime-startTime));
    }
}

No comments:

Post a Comment