Java Sort Array of Objects in Ascending and Descending Order | Arrays.sort() Method

preview_player
Показать описание
In this tutorial, we will see how to sort an array of primitives, strings and custom objects (employee) with a Comparable interface with an example.

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

You literally saved my interview ! Specially the employee sorting ! Great great thanks to you ! I even subscribed to you !

pranavvasani
Автор

Sir you are great. Thanks for teaching us.

samyakjain
Автор

Thank you so much you are an excellent teacher!

theuberman
Автор

How would you sort objects while using a non int property. The compareTo method requires that it returns an int because it comes from the Comparator interface?

DWEthiopia
Автор

what if i wanna compare to 2 separate fields in 2 separate circumstances, for example i have a class product with a name and a price and i wanna sort by name sometimes and sometimes by price what do i do

Ptoki
Автор

This is really clear explaining the Array.sort() method!!
I have a little question, though. If the salary is calculated by (hourly rate * hours), I can create a salary in the field like this:
private int hourlyRate;
private int hours;
private int salary = hourlyRate * hours;

With this process, can I still do exactly the same thing you did in the video?

fitybmn
Автор

hi, how do you sorted based from the frequency from the first letter?

muhammadshougi
Автор

you clearly explain how to sort objects, thank you. I also want to learn about inheritance hiearchy while sorting, if you have time can you solve such an example?

hakangurel
Автор

Can you please help me with this question ..
Q. Write a program to search the customer based on the customer's I'd using binary search algorithm where the array is {{"1001", "Raj", "Chennai"}, {"1008", "Akshay", "Pune"}, {"1002", "Simrath", "Amritsar"}, {"1005", "Ganesh", "Chennai"}}
1.Sample input:
1005
Sample output:
1005
Ganesh
Chennai

Sample input 2:
2345
Sample output:
No Record Found

apekshapatle
Автор

how to sort the employee object according to name ascending order and descending order

mahebubshaikh
Автор

Employee[] employees = {
new Employee(10, "Ramesh", 50000),
new Employee(20, "Tom", 60000),
new Employee(30, "John", 80000),
new Employee(40, "Tony", 30000)
};

JuanHernandez-hwbx
Автор

Why are you always printing them as String? I don't think it's mandatory and it's making the code unnecessarily complicated.

souvikgope
Автор

Lol okay it's quick but where is the formula? Come on you can't do the logic fundamentals ie while, for, then?

spitfirelast
Автор

You literally saved my interview ! Specially the employee sorting ! Great great thanks to you ! I even subscribed to you

dolevdo