@SuppressWarnings("unchecked") public static <T>void sort(List<T> list,Comparator<? super T> comparator){
  T[] array=list.toArray((T[])new Object[list.size()]);
  Arrays.sort(array,comparator);
  int i=0;
  ListIterator<T> it=list.listIterator();
  while (it.hasNext()) {
    it.next();
    it.set(array[i++]);
  }
}

@ SuppressWarnings ( "unchecked" ) public static < T > void sort ( List < T > list , Comparator < ? super T > comparator ) { T [ ] array = list . toArray ( ( T [ ] ) new Object [ list . size ( ) ] ) ; Arrays . sort ( array , comparator ) ; int i = 0 ; ListIterator < T > it = list . listIterator ( ) ; while ( it . hasNext ( ) ) { it . next ( ) ; it . set ( array [ i ++ ] ) ; } }
sorts the specified list using the specified comparator . the algorithm is stable which means equal elements don ' t get reordered .
