java 8 in lambda expression (the reference) -> {operation}

format:

(parameters) ->{statements; }

scenes to be used:

a) instead of using the original expression lamaba foreach loop.

b) with Lamaba complete expression to write an anonymous inner class, braces can write a lot less, so that the code looks cool a lot.

c) primary, Lambda allowed to function as an argument of a method (function as a parameter passed into the process).

 

1. traversal operation map

    public static void main(String[] args) {
        Map<Integer, String> map = new HashMap<Integer, String>();
        map.put(1, "1");
        map.put(2, "2");
        map.forEach((key, value) -> {
            log.info("{}:{}", key, value);
        });
    }

  

Guess you like

Origin www.cnblogs.com/ynhk/p/11541794.html