0

I am trying to sort an ArrayList using comparable interface. How do I sort ArrayList in descending or ascending order?

Zeina
  • 59
  • 6

1 Answers1

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

Community
  • 1
  • 1
keewi
  • 68
  • 3