I am trying to sort an ArrayList using comparable interface. How do I sort ArrayList in descending or ascending order?
Asked
Active
Viewed 54 times
1 Answers
2
You're able to sort an ArrayList if the elements implement Comparable. For example, Integers can be sorted with sort():
Collections.sort(arrayList)
Lists (and arrays) of objects that implement this interface can be sorted automatically by Collections.sort (and Arrays.sort).
from https://docs.oracle.com/javase/7/docs/api/java/lang/Comparable.html