/** * Filters out the non-unique values in an array. * <p> * Use Array.stream().filter() for an array containing only the unique values. * * @param elements input array * @return unique values in the array */ public static int[] filterNonUnique(int[] elements) { return Arrays.stream(elements) .filter(el -> indexOf(elements, el) == lastIndexOf(elements, el)) .toArray(); }
/** * Filters out the non-unique values in an array. * <p> * Use Array.stream().filter() for an array containing only the unique values. * * @param elements input array * @return unique values in the array */ public static int[] filterNonUnique(int[] elements) { return Arrays.stream(elements) .filter(el -> indexOf(elements, el) == lastIndexOf(elements, el)) .toArray(); }