Java Fundamentals - Lesson 41 - Stream API Part 3

preview_player
Показать описание
Are you new to Java development? Do you want to know what to start with? This is a complete stream dedicated to you - the junior developer or future developer.

- Java OCP 11 certification
- Learn Java basics
- Find a junior java developer role

If your target is at least one of the above, then this lesson streaming is for you. Join!

Don't forget to follow me on Twitter @laurspilca or LinkedIn for more posts and discussions.

Рекомендации по теме
Комментарии
Автор

Laurent, are there any "clues" to look for in order to determine which operations are terminal? I did not see anything obvious in the code complete window. Such a shortcut may be useful for interview purposes like timed coding tests.
I am following your Spring security series on Friday and enjoying it.

thethreestorms
Автор

Hello, Laurent. Hope you're doing well. I have a question on the distinct intermediate operation of streams. I tried this code:

// The code is the next:
List<Cat> catList = List.of(new Cat(1), new Cat(1), new Cat(2));


// The Cat equals implementation is the next:
public boolean equals(Object obj) {
if (obj instanceof Cat cat) {
return cat.age - this.age == 0;
} else return false;
}

What happens is that, when printing, it still prints three objects, even knowing that there are two that are "equals" (the ones with age=1) according to the equals implementation. What is wrong with my code? Can you help me understand why this happens?

MateoEstudiante
Автор

Hi, Laurentiu. Thank you for the lesson!

How are values passed through the pipeline? All together are being sent through the functions or each value separately is being sent (one by one)?

iondodon-programare
Автор

Hi, Laurentiu, can we perform the action with array using stream api which depends upon the position of the item in the list .. for example can we calculate sum of the diagonals of the 2d array using any of the stream API?

aniket
Автор

Hi @Laurentiu,

why do we have an exception here at the end?

Stream<Integer> numStream = Stream.of(10, 20, 30);
numStream.map(n -> n + 10).peek(s -> System.out.print(s));
numStream.forEach(s -> System.out.println(s));

many thanks for your effort

ramihichri
visit shbcf.ru