Wish u would have uploaded this video a day ago...The same exact question was asked to me in an interview on this Friday...Anyways..It s never too late...Thanks!
// get max marks in the list int hm = sl.stream().map(e -> e.getMarks()).max(Integer::compare).get(); System.out.println(hm); // Second highest sl.stream().filter(e -> e.getMarks() < hm).limit(1).forEach(e -> System.out.println(e.getName()));
When we apply stream alone it will return stream of student objects and we cannot directly apply integer operations on stream objects, To convert stream object to integer he used map.
Everyday brain refresher. In SQL world it would be like
SELECT * FROM students where marks = (SELECT MAX (marks) FROM students)
Thank you Naveen !!!
hello sir i am a college students am so interested in java because of your videos keep posting more videos daily thank you sir
Thank you Naveen
I was practicing your SQL series...very nice you have explained everything...especially practicing in "XAMPP".
Thank you sir
Excellent!
Can you please also share video on lower java versions and the latest version and its new features and impact on legacy core Java code.. @Naveen pls?
Amazing sir
Wish u would have uploaded this video a day ago...The same exact question was asked to me in an interview on this Friday...Anyways..It s never too late...Thanks!
@Suganth Deepak, for which company it was asked ?
@@shivamrastogi7652 striim
Sir please make a complete series on OOP in java...
please sir a series on java 8 features, including Stream API.
👍
Question: how can I find second highest number ?
Optional opt = studentList.stream().sorted(Collections.reverseOrder()).limit(2).skip(1).findFirst();
System.out.println(Arrays.toString(opt))
1.Create an array..
2. Use some sort (bubble sort)
3.return arr[n-2]. (n is length)
// get max marks in the list
int hm = sl.stream().map(e -> e.getMarks()).max(Integer::compare).get();
System.out.println(hm);
// Second highest
sl.stream().filter(e -> e.getMarks() < hm).limit(1).forEach(e -> System.out.println(e.getName()));
why we used map method? You did not tell.
When we apply stream alone it will return stream of student objects and we cannot directly apply integer operations on stream objects, To convert stream object to integer he used map.
First comment