I want to sort the getSal values in the myList. It should be a sorting algorithm implementation so that adding or removing objects does not affect the performance.
import java.util.*;
public class payment {
public String name;
public int salary;
void setName(String _name) {
name = _name;
}
String getName() {
return name;
}
void setSal(int sal) {
salary = sal;
}
int getSal() {
return salary;
}
public static void main(String[] args) {
ArrayList<payment> myList = new ArrayList<payment>();
payment a = new payment();
payment b = new payment();
payment c = new payment();
a.setName("John");
b.setName("Drake");
c.setName("Brad");
a.setSal(6000);
b.setSal(8000);
c.setSal(3000);
myList.add(a);
myList.add(b);
myList.add(c);
for (payment salary_employee : myList ) {
System.out.println(salary_employee.getSal());
}
for (payment name_employee : myList ) {
System.out.println(name_employee.getName());
}
// want the numbers to be ordered, 3000,6000,8000
}
}