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

By: Devoxx

1903   28   128154

Uploaded on 11/11/2015

The first thing visible in Java 8 is the lambdas, but the real power is in Streams. If you're interested in immersing into lambdas and streams, this is the session for you. We will start with lambda expressions, learn about how to use them and how they get implemented under the hood. Then we will swiftly move into learning about streams, the abstractions they provide, and a variety of operations we can do with them. We will conclude with a discussion about lazy evaluations, infinite streams, and parallel collections.

Comments (6):

By anonymous    2017-09-20

The helper methods from the accepted answer are not needed. Streams can be used with lambdas or usually shortened using Method References. 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) explains it better than me.

1 Convert List<String> to List<Integer>

List<String> l1 = Arrays.asList("1", "2", "3");
List<Integer> r1 =;

// the longer full lambda version:
List<Integer> r1 = -> Integer.parseInt(s)).collect(Collectors.toList());

2 Convert List<String> to int[]

int[] r2 =;

3 Convert String[] to List<Integer>

String[] a1 = {"4", "5", "6"};
List<Integer> r3 = Stream.of(a1).map(Integer::parseInt).collect(Collectors.toList());

4 Convert String[] to int[]

int[] r4 = Stream.of(a1).mapToInt(Integer::parseInt).toArray();

5 Convert String[] to List<Double>

List<Double> r5 = Stream.of(a1).map(Double::parseDouble).collect(Collectors.toList());

6 (bonus) Convert int[] to String[]

int[] a2 = {7, 8, 9};
String[] r6 =[]::new);

Lots more variations are possible of course.

Also see Ideone version of these examples. Can click fork and then run to run in the browser.

Original Thread

By anonymous    2017-09-20

Try something like this. I found this solution in a YT video I watched yesterday. Go to about 1:58:30

List<MyObjects> myList = createObjects();

Map<String, Optional<String>> myMappedList =
                         Collectors.maxBy((a, b) -> a.toString().length() - b.toString().length()))));

//Here's the output with your example (Using toString override in MyObjects Class):


{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 Subramaniam thought it important enough to talk about...

Original Thread

By anonymous    2017-11-27

this is good video

Original Thread

By anonymous    2018-05-09

if you are new to lambda's and java8 features [this is a great talk on those features](

Original Thread

Submit Your Video

If you have some great dev videos to share, please fill out this form.