当前位置:网站首页>Lambda quick start

Lambda quick start

2022-06-12 00:42:00 Leon_ Jinhai_ Sun

demand

​ We can call getAuthors Method to get the collection of Writers . Now you need to print all the documents that are younger than 18 The name of the writer , And pay attention to weight removal .

Realization

        // Print all children younger than 18 The name of the writer , And pay attention to weight removal 
        List<Author> authors = getAuthors();
        authors.
                stream()// Convert a collection into a stream 
                .distinct()// First remove the duplicate writers 
                .filter(author -> author.getAge()<18)// The screening age is less than 18 Of 
                .forEach(author -> System.out.println(author.getName()));// Traverse print name 

原网站

版权声明
本文为[Leon_ Jinhai_ Sun]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/163/202206120036471170.html