Created
November 3, 2012 13:39
-
-
Save yssharma/4007409 to your computer and use it in GitHub Desktop.
A sample method sorting a list by comparable and comparator (Confused Coders)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void someMethod(){ | |
/** Create a Emp List and add dummy values to Sort **/ | |
List<Employee> myEmpList = new ArrayList<Employee>(); | |
Employee emp = new Employee(); | |
emp.salary = 5000; | |
emp.name = "Arnold"; | |
myEmpList.add(emp); | |
emp = new Employee(); | |
emp.salary = 15000; | |
emp.name = "Clooney"; | |
myEmpList.add(emp); | |
emp = new Employee(); | |
emp.salary = 500; | |
emp.name = "Brad"; | |
myEmpList.add(emp); | |
/** Comparable **/ | |
Collections.sort(myEmpList); | |
/** Comparator **/ | |
Collections.sort(myEmpList, new SalaryComparator()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment