class abc {
String name;
int id;
int salary;
}
List list<abc>=new ArrayList();
Object of abc should be store based on sorted salary in List like max salary will be stored first then 2nd max will be stored then 3rd and soo on.
class abc {
String name;
int id;
int salary;
}
List list<abc>=new ArrayList();
Object of abc should be store based on sorted salary in List like max salary will be stored first then 2nd max will be stored then 3rd and soo on.
it's
List<abc> list=new ArrayList<>();
use
list.sort(Comparator<abc>).
or make abc implements Comparable and define the compareTo method. then use
list.sort()
If you mean to sort the list you can use Collections.sort api.
If you mean to store it in dp sorted ( as you used java-ee tag) it will be stored in dp sorted unless its being cascaded by another object.
There are 2 ways to do sorting on a custom data type :
1) Comparator
2) Comparable
Using Comparable
class abc implements Comparable<abc> {
String name;
int id;
int salary;
public int compareTo(abc t1){
return t1.salary - this.salary;
}
}
Now use Collections.sort()
on the arraylist, which would sort it for you.