Luciano Assis wrote:Oh ok Leandro.
But im both situations the object have to implements Comparator/Comparable right?
Thank's for the explanation.
So. You can sort passing a Comparator or not. If you don't pass a comparator, then the list type and the array type must implement Comparable, otherwise you'll get compile error and runtime exception (ClassCastException), respectively.
Comparator is normally used when you want to have different ways to sort the same object. You'll probably implement this using an inner class, then you would invoke Arrays.sort(T[] a, Comparator<? super T> c) and Collections.sort(List<T> list, Comparator<? super T> c).