Util { @SuppressWarnings("unchecked") public static <T> T[] removeValues(T[] values, Predicate<T> shouldRemove, Class<T> type) { Collection<T> collection = new ArrayList<>(values.length); for (T value : values) { if (shouldRemove.negate().test(value)) { collection.add(value); } } T[] array = (T[]) Array.newInstance(type, collection.size()); return collection.toArray(array); } private  Util(); static void checkArgument(boolean expression,
                                   String errorMessageTemplate,
                                   Object... errorMessageArgs); static T checkNotNull(T reference,
                                   String errorMessageTemplate,
                                   Object... errorMessageArgs); static void checkState(boolean expression,
                                String errorMessageTemplate,
                                Object... errorMessageArgs); static boolean isDefault(Method method); static String emptyToNull(String string); @SuppressWarnings("unchecked") static T[] removeValues(T[] values, Predicate<T> shouldRemove, Class<T> type); @SuppressWarnings("unchecked") static T[] toArray(Iterable<? extends T> iterable, Class<T> type); static Collection<T> valuesOrEmpty(Map<String, Collection<T>> map, String key); static void ensureClosed(Closeable closeable); static Type resolveLastTypeParameter(Type genericContext, Class<?> supertype); static Object emptyValueOf(Type type); static String toString(Reader reader); static byte[] toByteArray(InputStream in); static String decodeOrDefault(byte[] data, Charset charset, String defaultValue); static boolean isNotBlank(String value); static boolean isBlank(String value); static final String CONTENT_LENGTH; static final String CONTENT_ENCODING; static final String RETRY_AFTER; static final String ENCODING_GZIP; static final String ENCODING_DEFLATE; static final Charset UTF_8; static final Charset ISO_8859_1; static final Type MAP_STRING_WILDCARD; }
@Test public void removesEvenNumbers() { Integer[] values = new Integer[] {22, 23}; assertThat(removeValues(values, (number) -> number % 2 == 0, Integer.class)) .containsExactly(23); }