src/share/classes/java/util/Collections.java
Print this page
*** 150,159 ****
--- 150,162 ----
* detects that the natural ordering of the list elements is
* found to violate the {@link Comparable} contract
*/
public static <T extends Comparable<? super T>> void sort(List<T> list) {
Object[] a = list.toArray();
+ if(a.length <= 1) {
+ return;
+ }
Arrays.sort(a);
ListIterator<T> i = list.listIterator();
for (int j=0; j<a.length; j++) {
i.next();
i.set((T)a[j]);
*** 212,226 ****
* @throws IllegalArgumentException (optional) if the comparator is
* found to violate the {@link Comparator} contract
*/
public static <T> void sort(List<T> list, Comparator<? super T> c) {
Object[] a = list.toArray();
Arrays.sort(a, (Comparator)c);
! ListIterator i = list.listIterator();
for (int j=0; j<a.length; j++) {
i.next();
! i.set(a[j]);
}
}
/**
--- 215,232 ----
* @throws IllegalArgumentException (optional) if the comparator is
* found to violate the {@link Comparator} contract
*/
public static <T> void sort(List<T> list, Comparator<? super T> c) {
Object[] a = list.toArray();
+ if(a.length <= 1) {
+ return;
+ }
Arrays.sort(a, (Comparator)c);
! ListIterator<T> i = list.listIterator();
for (int j=0; j<a.length; j++) {
i.next();
! i.set((T) a[j]);
}
}
/**