private <T>List<T> toSortedList(T[] array,Comparator<T> comparator){
  List<T> list=new ArrayList<>();
  Collections.addAll(list,array);
  Collections.sort(list,comparator);
  return list;
}

private < T > List < T > toSortedList ( T [ ] array , Comparator < T > comparator ) { List < T > list = new ArrayList < > ( ) ; Collections . addAll ( list , array ) ; Collections . sort ( list , comparator ) ; return list ; }
creates a sorted list from an array of elements using the given classcomparator .
