Get a Taste of Lambdas and Get Addicted to Streams by Venkat Subramaniam

Devoxx · 496K views · 2015 · 2:46:53

Open on YouTube

Functional programmingSoftware practice, open source & careerstalk

Why Stack Overflow recommends it

Stack Overflow users link it when answering Java 8 lambda and stream questions, to explain stream operations, avoiding mutation in parallel streams, and cleaner lambda-based code.

Recommended by 5 people across 5 different months, 2016 to 2020.

What it is

A nearly three-hour Devoxx conference session in which Venkat Subramaniam teaches Java 8 lambda expressions and the Streams API through live coding. It covers how lambdas work under the hood, stream operations and abstractions, lazy evaluation, infinite streams, and parallel collections.

What people said

Strong rec Lonestar · 2020-06 · Stack Overflow · on “Issue with Refactoring the existing code using Streams (Java8)”

The problem is, that the lambda expression is still quite complex. If I pretend that it is hidden as extracted to a method, then what will remain in refractored version is just conversion one list to another one by stream. Quite ok, but maybe not that needed. I would refractor that block lambda to several functions to have overall more understandable code (hopefully). I can highly suggest following video: Get a Taste of Lambdas and Get Addicted to Streams by Venkat Subramaniam [this video]

Recommends TJA · 2016-06 · Stack Overflow · on “How to run 2 tasks in parallel in java?”

By two tasks do you mean two threads, if not then have a look at this as it nicely shows how to use lambdas in Java 8 to easily kick off separate threads [this video]

Recommends Stan Kurdziel · 2016-08 · Stack Overflow · on “Lambda expression to convert array/List of String to array/List of Integers”

The helper methods from the accepted answer are not needed. Streams [LINK] can be used with lambdas or usually shortened using Method References [LINK] . Streams enable functional operations. map() converts the elements and collect(...) or toArray() wrap the stream back up into an array or collection. Venkat Subramaniam's talk (video) [this video] explains it better than me. 1 Convert List<String> to List<Integer> List<String> l1 = Arrays.asList("1", "2", "3"); List<Integer> r1 = l1.stream().map(Integer::parseInt).collect(Collectors.toList()); // the longer full lambda version: List<Integer> r1 = l1.stream().map(s -> Integer.parseInt(s)).collect(Collectors.toList()); 2 Convert List<String> to int

Recommends Nick Ziebert · 2017-03 · Stack Overflow · on “How to create a map collecting on max value”

Try something like this. I found this solution in a YT video I watched yesterday. Go to about 1:58:30 [this video] List<MyObjects> myList = createObjects(); Map<String, Optional<String>> myMappedList = myList.stream() .collect(Collectors.groupingBy(MyObjects::getName, Collectors.mapping(MyObjects::getidSet, Collectors.maxBy((a, b) -> a.toString().length() - b.toString().length())))); //Here's the output with your example (Using toString override in MyObjects Class): System.out.println(myMappedList); {CH2OH=Optional[223,256,295], CH2CH2OH=Optional[255,310]} By "max", the comparator is looking for the idset with the longest string length. Hope this helps, I thought this was a good question. Venkat

Recommends asdofindia · 2020-09 · Stack Overflow · on “java 8 parallelStream().forEach Result data loss”

You lose the benefits of using stream (and parallel stream) when you try to do mutation. As a general rule, avoid mutation when using streams. Venkat Subramaniam explains why [this video] . Instead, use collectors. Also try to get a lot accomplished within the stream chain. For example: System.out.println( IntStream.range(0, 200000) .filter(i -> i % 2 == 0) .mapToObj(String::valueOf) .collect(Collectors.toList()).size() ); You can run that in parallelStream by adding .parallel()