Intermediate and terminal operation in Stream Java 8 Interview Questions | Difference | Code Decode

preview_player
Показать описание
In this video of code decode we have explained what is intermediated what is terminal operation and difference between them. We have also explained it with the help of examples

Udemy Course of Code Decode on Microservice k8s AWS CICD link:

Course Description Video :

What is an Intermediate operation

The operations which return another stream as a result are called intermediate operations. V imp part, they are lazy.
Eg:

filter(), map(), distinct(), sorted(), limit(), skip()

What is Terminal operation
The operations which return non-stream values like primitive or object or collection or return nothing are called terminal operations

You can chain multiple intermediate operations and none of them will do anything until you invoke a terminal operation. At that time, all of the intermediate operations that you invoked earlier will be invoked along with the terminal operation.

Eg:

forEach(), toArray(), reduce(), collect(), min(), max(), count(), anyMatch(), allMatch(), noneMatch(), findFirst(), findAny()

Intermediate Operations

They return stream.
They can be chained together to form a pipeline of operations.
Pipeline of operations may contain any number of intermediate operations.
Intermediate operations are lazily loaded.
They don’t produce end result.

Terminal Operations

They return non-stream values.
They can’t be chained together.
Pipeline of operations can have maximum one terminal operation, that too at the end.
Terminal operations are eagerly loaded.
They produce end result.

Subscriber and Follow Code Decode

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

Great content . Very well explained . Since last two days i was going through the full list of Java 8 Interview Questions(New Features) 25 / 25 . Loved it . Just done . Many thanks for the efforts . Just one quick thing, below videos are repetative
19 same as 17
20 same as 15
22 same as 14
23 same as 16
24 same as 13

shalabhpareek
Автор

Mam can you please arrange playlist of Java 8 features.
So that we can go through with proper learning order
(Ex: Lamda => functional interface => stream=> intermediate and terminal operation, map flatmap.)

Thanks in advanced 🙂

RockMB
Автор

Your videos are so helpful. Thank you for your efforts in making all these videos.Can you please make a video series on Junit and Mockito

lakshmichepeni
Автор

Thanks !! Although I think you already had covered these concepts in earlier videos.

akashsaha
Автор

Also ma'am please cover remaining all design pattern questions as well as mysql question like indexing, deleting duplicate records and many more, very big request 😊

shubhammhetre
Автор

Can you please explain the @Transaction how internal Work

mitulshah
Автор

As i have read, stream can not modify the collection values... But in last example we are using return e.getName() and we are not returning the final result to any other reference... So does it mean we are changing the original list(emplist)?... How is this possible? Can you elaborate, I am bit confused here

ankitratnani
Автор

Hey .. Have you covered map vs flatmap with demo anywhere ?? If not, can u please make a video on that

varunshrivastava
Автор

Can you please Explain How to Run Spring Application without EnableAutoConfigration

mitulshah
Автор

Hi, As discussed in video about terminal and intermediate operations. terminal operation always will not call the method execution. Plz check the below example if I have list of integers calling the makedouble() method inside intermediate operation map and then use count of terminate operation. then replace count() terminal operation with forEach(System.out::print) now double method will call. method execution called when we are using terminal operation on the result of intermediate operations.

public static void main(String[] args) {
List<Integer> list = Arrays.asList(1, 4, 2, 6, 9);

Predicate<Integer> pr = a -> (a % 2 == 0);

-> pr.test(i)).count() + "<>");

list.stream().filter(i -> pr.test(i)).map(res -> res +





+

execute((String name, int a) -> System.out.print(name + "<>" + a));

Test2 test2 = n -> n % 2 == 0;

if (test2.fun(2)) {
System.out.println("is even");
}
}

private static Integer doubleexe(Integer a) {

return a * a;
}

udaykiran-qzmn
Автор

Can you please Explain SOLID Principal

mitulshah
Автор

Can you please Explain "How to achieve prototype bean Injection on Singleton Beans."

mitulshah
join shbcf.ru