Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Collection<customObject> list = new ArrayList<customObject>();
- Collection list = new ArrayList();
- Comparator comparator = new new Comparator<CustomObject>() {
- public int compare(CustomObject c1, CustomObject c2) {
- return c2.getId() - c1.getId(); // use your logic
- }
- };
- Collections.sort(list, comparator); // use the comparator as much as u want
- System.out.println(list);
- public class CustomComparator implements Comparator<CustomObject>
- {
- @Override
- public int compare(CustomObject o1, CustomObject o2) {
- return o1.getId().compareTo(o2.getId());
- }
- }
- Collections.sort(list, new CustomComparator());
- Collections.sort(allMatching, new Comparator<ClassOne>() {
- @Override public int compare(final ClassOne o1, final ClassOne o2) {
- if (o1.getMethodToSort() > o2.getMethodToSort()) {
- return 1;
- } else if (o1.getMethodToSort() < o2.getMethodToSort()) {
- return -1;
- }
- return 0;
- }
- });
Add Comment
Please, Sign In to add comment