private static <T>void insertIntoSortedList(List<T> list,Comparator<T> comparator,T newItem){
  int index;
  for (index=0; index < list.size(); index++) {
    if (comparator.compare(list.get(index),newItem) > 0)     break;
  }
  list.add(index,newItem);
}

private static < T > void insertIntoSortedList ( List < T > list , Comparator < T > comparator , T newItem ) { int index ; for ( index = 0 ; index < list . size ( ) ; index ++ ) { if ( comparator . compare ( list . get ( index ) , newItem ) > 0 ) break ; } list . add ( index , newItem ) ; }
given a sorted list , inserts a new element in the correct position to maintain the sorted order .
