Lambda表达式

@Test
    public void test2(){
        //eg1
        new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("HelloWorld");
            }
        }).start();

        new Thread(() -> System.out.println("HelloWorld")).start();


        //eg2
        List<Integer> list = Arrays.asList(1, 2, 3, 4, 5, 6, 7);
        for(Integer n: list) {
            System.out.println(n);
        }

        list.forEach(n -> System.out.println(n));

        System.out.println("------------------------");
        //eg3
        for(Integer n : list) {
            int x = n * n;
            System.out.println(x);
        }

        list.stream().map(n -> n * n).forEach(n -> System.out.println(n));
    }

https://www.jianshu.com/p/6de5db0e40f7

https://blog.csdn.net/qq_29411737/article/details/80835658

posted @ 2019-02-13 11:26  Peter.Jones  阅读(87)  评论(0编辑  收藏  举报