Java Streams Interview Question - 07 - Find Max and Min Numbers using Streams

preview_player
Показать описание
Java Streams Interview Question - 07 - Find Max and Min Number using Streams

Schedule a meeting in case of any queries/guidance/counselling:

~~~Subscribe to this channel, and press bell icon to get some interesting videos on Selenium and Automation:

Follow me on my Facebook Page:

Let's join our Automation community for some amazing knowledge sharing and group discussion on Telegram:

Naveen AutomationLabs Paid Courses:
GIT Hub Course:

Java & Selenium:

Java & API +POSTMAN + RestAssured + HttpClient:
Рекомендации по теме
Комментарии
Автор

We can also use this using lambda:

int result = list.stream().max((e1, e2) -> e1-e2).get();
int result = list.stream().min((e1, e2) -> e2-e1).get();

anitsarker
Автор

same for min with min it will be easy thi way

rajnikanthofficial
Автор

This is another way of solution:

List<Integer> list1 = Arrays.asList(-1, 0, 1, 3, 10, 20, 30, 15, 1, 13, 1, 2, 2, 10, 40, 19, 3);
Integer maxnum = list1.stream().reduce(1, (a, b) -> a > b ? a : b);
System.out.println(maxnum);
Integer minnum = list1.stream().reduce(1, (a, b) -> a < b ? a : b);
System.out.println(minnum);

nikunjpatel
Автор

we can use this better than others

-> value).min().getAsInt()));

Srikanthb
Автор

how about:

List<Integer> list6 = List.of(10, 20, 30, 25, 21, 0, 30, 100, 999, 3, 33);

Optional<Integer> max = list6.stream()
.max(Integer::compareTo);

Optional<Integer> min = list6.stream()
.min(Integer::compareTo);

watchmeplayit
Автор

It can be done with reducer() and method reference:
Integer result =

postoronnii__
Автор

In java we use that for converting an integer to string

gottepavani
Автор

SummaryStatistics is the best way to find out max, min, average etc.

jitendrapatil
Автор

We can simply Write : IntSummaryStatistics collect 
Ouput is : : IntSummaryStatistics{count=20, sum=390, min=10, max=29}

maheshuma
Автор

List<Integer> o = List.of(1, 20, 30, 4, 4, 30, 30);
Integer i =
System.out.println(i);

shaikjareena
Автор

Please let us know the time and space complexity of these solution also in comparison with the best solution, as interviewer focus more on that

ashutoshsingh-uhio
Автор

@naveen how to find second largest number through stream

RaahithyaYadav
Автор

How about this one?
OptionalInt maxOptional =
System.out.println("Max = "+maxOptional.getAsInt());

jaleelpasha
join shbcf.ru