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
		
		
	
		
	}
	
}

Hey Guys: I Have sorted my question my self.
For all of those who are interested. Have a look.
Regards, A

import java.util.*;
import java.text.*;

public class payment implements Comparable<payment> {

	public String name;//null
	public int salary; //0
	
	void setName(String _name) {
		name = _name;
	}
	
	String getName() {	
		return name;	
	}
	
	void setSal(int sal) {
		salary = sal;
	}
	
	int getSal() {
	return salary;	
	}
	
	public int compareTo(payment p) {
		if (salary > p.getSal())      //up the stack
			return -1;
		else if (salary < p.getSal()) //down the stack
			return 1;
		else
			return 0;
	}

	public String toString() {
		return String.format("%-20s %s", name, NumberFormat.getCurrencyInstance().format(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();
		payment d = new payment();
		payment e = new payment();
		payment f = new payment();
		
		a.setName("John");
		b.setName("Drake");
		c.setName("Brad");
		d.setName("Glen");
		e.setName("Migena");
		f.setName("Ali");
		
		a.setSal(3000);
		b.setSal(2000);
		c.setSal(7000);
		d.setSal(5000);
		e.setSal(22000);
		f.setSal(11000);
		
		myList.add(a);
		myList.add(b);
		myList.add(c);
		myList.add(d);
		myList.add(e);
		myList.add(f);
		

		
		
		for (payment salary_employee : myList ) {
			System.out.println(salary_employee.getSal());
		}
		
		for (payment name_employee : myList ) {
			System.out.println(name_employee.getName());
		
		}
		
		Collections.sort(myList);
		for (payment p : myList ) {
			System.out.println(p);
			
		}
		
		System.out.println("*This system has powerful functionality*");
			
		
	}
}



			
/*This code is junk.  I solved the question, but you know why I'l always keep this code in here,
because you wrote it, and I love you, you know why, because you are my life.
			 
			<3 int minimum;
			<3 if(a<minimum)
			
*/

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
		
		
	
		
	}
	
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.