Java 8 Stream - How to Sort a List using lambda | Example | Java Techie

  Рет қаралды 57,792

Java Techie

Java Techie

5 жыл бұрын

This video explain you How to sort a list in java 8 using lambda expression and stream API even we use Comparator for custom sorting order with stream api - real time example
GitHub:
github.com/Java-Techie-jt/java8
Blogs:
javagyanmantra.wixsite.com/we...
Facebook:
/ 919464521471923
guys if you like this video please do subscribe now and press the bell icon to not miss any update from Java Techie

Пікірлер: 89
@subhashsahu9930
@subhashsahu9930 Ай бұрын
Thanks for sharing this valuable knowledge
@nameshd658
@nameshd658 3 жыл бұрын
Wow man... I'm doing your programming series one by one every day... This is day #7.. Thanks a lot bro. Awesome tutorial !!!
@vandana89100
@vandana89100 3 жыл бұрын
Hats off to you for making life easier👍🏻
@BooSgu
@BooSgu Жыл бұрын
Simple explanation and easy to understand. Thank you very much.
@BookWormsOriginal
@BookWormsOriginal 4 жыл бұрын
The most simplistic and to the point explanation, you made my day! Thanks a lot! You deserve to be subscribed to!
@Javatechie
@Javatechie 4 жыл бұрын
Thank you so much subham
@baibhavghimire3827
@baibhavghimire3827 3 жыл бұрын
You deserve more subscription..I am doing that..Thanks man for going through the basis and connecting dots.
@mohammedshabbir1347
@mohammedshabbir1347 3 жыл бұрын
Awesome explanation. Thanks Basant.
@neutral911
@neutral911 4 жыл бұрын
Excellent Bro... I'm very satisfied with this explanation.. Thanks a lot and keep posting videos...
@siyedyoussef3202
@siyedyoussef3202 5 жыл бұрын
Great java 8 playlist video 👍👍👍👍
@debaprasadsahoo3707
@debaprasadsahoo3707 5 жыл бұрын
Really this is a very good explanation for me.
@mohan4459
@mohan4459 5 жыл бұрын
Nice explanation ... Thank you so much
@Technoverse_solutions
@Technoverse_solutions 3 ай бұрын
Your explanation was simply superb.......................#CRISTAL CLEAR #take_a_bow
@manimarankrishnamoorthy8172
@manimarankrishnamoorthy8172 4 жыл бұрын
Nicely explained..Great.
@sureshsadanala4639
@sureshsadanala4639 5 жыл бұрын
nicely explained 👍.. waiting for more videos 😊
@amitkharbade
@amitkharbade 2 жыл бұрын
Thanks for another useful tutorial
@kishordige4654
@kishordige4654 2 жыл бұрын
Thank you! You are a great Teacher
@TheMihan123
@TheMihan123 4 жыл бұрын
Thanks ! nicely explained .
@mydreamworld29
@mydreamworld29 3 жыл бұрын
Well explained. Thanks
@niranjanp8194
@niranjanp8194 2 жыл бұрын
Perfect example bro. keep it up.
@ramanshrestha3851
@ramanshrestha3851 3 жыл бұрын
Nice video, keep uploading useful videos related to Java. Thanks
@fjkldhakljf
@fjkldhakljf Жыл бұрын
Great work sir , I admire your ability to give motivation for examples and follow through steps of why this way is better than alternatives
@Javatechie
@Javatechie Жыл бұрын
Keep learning 😃
@umaparvathi606
@umaparvathi606 3 жыл бұрын
All the topics very nice sir
@tussharsurya5829
@tussharsurya5829 5 жыл бұрын
Well explained 😇
@sameer838
@sameer838 2 жыл бұрын
Great
@berkcanulubas1318
@berkcanulubas1318 Ай бұрын
thank you for your great video
@saurabh7489
@saurabh7489 2 жыл бұрын
Great video. Thank you very much. Here is what I do for a list of objects: employees.sort(Comparator.comparing(Employee::getSalary)); employees.sort(Comparator.comparing(Employee::getSalary).reversed());
@Javatechie
@Javatechie 2 жыл бұрын
It's always recommend to use stream in single pipeline rather than use collections utility method
@saurabh7489
@saurabh7489 2 жыл бұрын
@@Javatechie Thanks for the information 🙂 I just felt that if all I want to do is sort the stream and not worry about modifying the original list, and not perform any other operation like 'filtering' or 'mapping' then creating a stream will incur extra overhead.
@taufiquealam4125
@taufiquealam4125 5 жыл бұрын
You are simply Wow. Nice explanation. Request to come up with new things in Java 8 that would be highly appreciated.
@Javatechie
@Javatechie 5 жыл бұрын
After finish this stream API we will start date API series
@taufiquealam4125
@taufiquealam4125 5 жыл бұрын
@@Javatechie Thank you...
@milimishra6447
@milimishra6447 28 күн бұрын
Good one
@ANKITCHOUDHARYankitkrchy
@ANKITCHOUDHARYankitkrchy 2 жыл бұрын
Commendable job
@sumitjain3526
@sumitjain3526 Жыл бұрын
Thank you so much
@ILuvBilli
@ILuvBilli 5 жыл бұрын
Superbbbb
@sinurao1017
@sinurao1017 3 жыл бұрын
Super JT
@vipinvenugopal3166
@vipinvenugopal3166 2 жыл бұрын
Thanks
@sarojgupta8181
@sarojgupta8181 Жыл бұрын
wow its superb :)
@Javatechie
@Javatechie Жыл бұрын
Thanks buddy 😊
@RaulSC9
@RaulSC9 4 жыл бұрын
Thanks!!
@maruthidanda2364
@maruthidanda2364 2 жыл бұрын
Super super
@rahulkaranjavkar7994
@rahulkaranjavkar7994 5 жыл бұрын
Thanks...
@Explorewith4x4
@Explorewith4x4 Жыл бұрын
NYC video 17:18 ❤
@sowmyadara
@sowmyadara 4 жыл бұрын
Great explanation.. at 2:58 why can't we use like sorted(Comparator::reveseOrder)
@Javatechie
@Javatechie 4 жыл бұрын
We can't represent this as Method reference
@sowmyadara
@sowmyadara 3 жыл бұрын
@Java Techie ... Thank you
@saswatidas6217
@saswatidas6217 4 жыл бұрын
Could you please explain more about method reference ?
@naveenc4963
@naveenc4963 5 жыл бұрын
Nice explanation bro Can you share the Java 8 features example codes
@Javatechie
@Javatechie 5 жыл бұрын
Link mentioned in video description
@ashishchoudhary9824
@ashishchoudhary9824 3 жыл бұрын
Hii vasant, how will we do customized sorting in descending order using method reference ? (Comparator.comparing(Employee::getName)). This will give me sorting in ascending order but i want in descending order. Or i want sorting based on length of employee name, how will do using stream api ? Thanks.
@RealSlimShady-um6gf
@RealSlimShady-um6gf 8 ай бұрын
While sorting why do you want to downcast Long to int? Either while declaring the field you should have made it as int or proceed with logic for Long which is a much better real time example
@Saravanan-lj9so
@Saravanan-lj9so 4 жыл бұрын
Man, Why you did not put video 15 years back ?I would have been very good developer.You are great.
@Javatechie
@Javatechie 4 жыл бұрын
Thank you 😀
@pankajkm884
@pankajkm884 2 жыл бұрын
getName method is not static method. It is instance method. So, how you can call it by Class reference method?
@Javatechie
@Javatechie 2 жыл бұрын
Method reference doesn't mean to access only static method all getter method you can access while performing mapping
@pradiptagure7492
@pradiptagure7492 3 жыл бұрын
Very good tutorial. It helped me. But one question, at the comparing example, it is sorting ascending by default. If I need to do, descending as well, how to achieve that?
@Javatechie
@Javatechie 3 жыл бұрын
You can call reverseOrder ()
@pradiptagure7492
@pradiptagure7492 3 жыл бұрын
@@Javatechie Thanks
@hardikjotangia2642
@hardikjotangia2642 3 жыл бұрын
Sir, when I am doing shorting I want new shorted list, How to achieve this?
@Javatechie
@Javatechie 3 жыл бұрын
Yes we can , you need to do something like list.stream().sort(Comparator.comparing("ADD COMPARISON LOGIC")).collect(Collectors.toList());
@vishalpradhan9881793197
@vishalpradhan9881793197 2 жыл бұрын
writing comment from terminal
@raghunathhembram9962
@raghunathhembram9962 8 ай бұрын
sir can we sort the list of number without using sorted method by using stream api in java
@Javatechie
@Javatechie 8 ай бұрын
import java.util.List; import java.util.ArrayList; import java.util.stream.Collectors; import java.util.Comparator; public class Main { public static void main(String[] args) { List numbers = List.of(3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5); List sortedNumbers = new ArrayList(); while (!numbers.isEmpty()) { Integer min = numbers.stream() .min(Comparator.naturalOrder()) .orElse(null); if (min != null) { sortedNumbers.add(min); numbers.remove(min); } } System.out.println(sortedNumbers); } }
@vishalpradhan9881793197
@vishalpradhan9881793197 2 жыл бұрын
writing comment from UI
@vamsikondaparthik9934
@vamsikondaparthik9934 2 жыл бұрын
Thanks for the Tutorial. In Java 11 i am unable to call getter and setter methods in comparing method like below: listEmployee.stream().sorted(Comparator.comparing(emp->emp.getName) Could you please help me with this.
@Javatechie
@Javatechie 2 жыл бұрын
Do you have setter and getter method define in your employee class
@vamsikondaparthik9934
@vamsikondaparthik9934 2 жыл бұрын
@@Javatechie i think its just STS not showing the methods … when i wrote manually there is no error
@Ravinanik
@Ravinanik 7 ай бұрын
How to sort reverse using comparing method
@sujithg5873
@sujithg5873 5 жыл бұрын
Can u detailed explanation for method reference
@Javatechie
@Javatechie 5 жыл бұрын
Ok Will do
@sujithg5873
@sujithg5873 5 жыл бұрын
@@Javatechie thanks ☺️☺️
@johngather4055
@johngather4055 4 жыл бұрын
thnks why u are overriding equals and hashcode for custom employee
@Javatechie
@Javatechie 4 жыл бұрын
If you won't override equals and hashcode then we can't compare object This is what also contract between these two method
@saurabhkailashchandrapuran8609
@saurabhkailashchandrapuran8609 3 жыл бұрын
how to sort on custom two fields like with name and salary both at a time
@Javatechie
@Javatechie 3 жыл бұрын
Inside lambda we need to go for if condition
@oguzhan2393
@oguzhan2393 Жыл бұрын
you are really doing great things. I was watching a guy who was really idiot. called amigo. something. But mate you are really doing good things thanks.
@Javatechie
@Javatechie Жыл бұрын
Thanks buddy glad that i am delivering the content which people can understand. Keep learning
@kishyash1
@kishyash1 2 жыл бұрын
Hii vasant, how will we do customized sorting in descending order using method reference ? (Comparator.comparing(Employee::getName)). This will give me sorting in ascending order but i want in descending order.
@Javatechie
@Javatechie 2 жыл бұрын
Just use reversed () method
@kishyash1
@kishyash1 2 жыл бұрын
@@Javatechie Thanks alot and response also so fast
@Javatechie
@Javatechie 2 жыл бұрын
Is it works?
@kishyash1
@kishyash1 2 жыл бұрын
@@Javatechie yes
@Ankit-vp7nt
@Ankit-vp7nt 4 жыл бұрын
Bro search by name and name has casesensitive means some name start with upper case then how to sort in video 15:15 min
@Javatechie
@Javatechie 4 жыл бұрын
Why doing stream you should forcefully either make them lowercase or uppercase something like employees.stream().sorted(Comparator.comparing(emp->emp.getName().toLowerCase())).forEach(System.out::println);
@Ankit-vp7nt
@Ankit-vp7nt 4 жыл бұрын
@@Javatechie Collections.sort(employee,(o1,o2)-> o1.getName().compareToIgnoreCase(o2.getName())); like that working but in stream is not working
@Javatechie
@Javatechie 4 жыл бұрын
@@Ankit-vp7nt let you know once I will check
@omsonschicago5872
@omsonschicago5872 4 жыл бұрын
Thank you so much
Java 8 Stream API | forEach & filter Method example | Java Techie
21:56
Дибала против вратаря Легенды
00:33
Mr. Oleynik
Рет қаралды 4,1 МЛН
Did you believe it was real? #tiktok
00:25
Анастасия Тарасова
Рет қаралды 12 МЛН
Can You Draw A PERFECTLY Dotted Line?
00:55
Stokes Twins
Рет қаралды 78 МЛН
Lambda Expressions in Java - Full Simple Tutorial
13:05
Coding with John
Рет қаралды 710 М.
Java 8 Streams | map() and reduce()  Example | JavaTechie
18:11
Java Techie
Рет қаралды 95 М.
Stream API in Java
26:04
Telusko
Рет қаралды 280 М.
28. Streams in Java8 | Collections in Java - Part7
1:15:10
Concept && Coding - by Shrayansh
Рет қаралды 29 М.
How Spring Boot Application Work Internally | Example | Java Techie
18:06
Functional Interface | Lambda Expression in Java
13:56
Telusko
Рет қаралды 137 М.
Что не так с яблоком Apple? #apple #macbook
0:38
Не шарю!
Рет қаралды 130 М.
Will the battery emit smoke if it rotates rapidly?
0:11
Meaningful Cartoons 183
Рет қаралды 37 МЛН
ПОКУПКА ТЕЛЕФОНА С АВИТО?🤭
1:00
Корнеич
Рет қаралды 3,3 МЛН