public static < T > List < T > getUnique ( Collection < T > collection ) { HashSet < T > set = new HashSet <> ( ) ; List < T > out = new ArrayList <> ( ) ; for ( T t : collection ) { if ( ! set . contains ( t ) ) { out . add ( t ) ; set . add ( t ) ; } } return out ; }
Returns a list containing only unique values in a collection