public static <T>boolean containsDuplicates(List<T> list,Comparator<T> comparator){
  Collections.sort(list,comparator);
  T previous=null;
  for (  T entry : list) {
    if (previous != null && previous.equals(entry)) {
      return true;
    }
    previous=entry;
  }
  return false;
}

public static < T > boolean containsDuplicates ( List < T > list , Comparator < T > comparator ) { Collections . sort ( list , comparator ) ; T previous = null ; for ( T entry : list ) { if ( previous != null && previous . equals ( entry ) ) { return true ; } previous = entry ; } return false ; }
checks whether the given list contains duplicates . list entries are compared using the given comparator .
