liners No need to use “return” for one line statements Same scope You can use “this” inside a lambda expression, they also captures variables (by making them effective final). // Inline without an argument () -> "Hello" // With code block as a body () -> { String name = "John"; return "Hello " + name; } // With parameter lastName -> "Mr. " + lastName // With explicit type of parameters (int a, int b) -> a + b @bsideup
persons) { if (person.age() > maximum) { maximum = person.age(); } } assert maximum == maxAge; int maximum = persons.stream() .mapToInt(Person::age) .max() .orElse(Integer.MIN_VALUE); assert maximum == maxAge;
Old Streams @bsideup Explanation Collections are already heavily optimised Streams were designed and optimised with concurrency in mind, so they can handle concurrent grouping, old code is not
44274 Old Streams @bsideup Explanation Not a good quality of old code, but one of the most popular ways of doing such things Heavily optimised algorithms under Stream implementation