private static <E>Object[] removeDupes(Object[] array,Comparator<? super E> comparator){
  int size=1;
  for (int i=1; i < array.length; i++) {
    Object element=array[i];
    if (unsafeCompare(comparator,array[size - 1],element) != 0) {
      array[size]=element;
      size++;
    }
  }
  if (size == array.length) {
    return array;
  }
 else {
    Object[] copy=new Object[size];
    System.arraycopy(array,0,copy,0,size);
    return copy;
  }
}

private static < E > Object [ ] removeDupes ( Object [ ] array , Comparator < ? super E > comparator ) { int size = 1 ; for ( int i = 1 ; i < array . length ; i ++ ) { Object element = array [ i ] ; if ( unsafeCompare ( comparator , array [ size - 1 ] , element ) != 0 ) { array [ size ] = element ; size ++ ; } } if ( size == array . length ) { return array ; } else { Object [ ] copy = new Object [ size ] ; System . arraycopy ( array , 0 , copy , 0 , size ) ; return copy ; } }
returns an array that removes duplicate consecutive elements , according to the provided comparator . note that the input array is modified . this method does not support empty arrays .
