CollectionUtilsExtended { public static <TargetType> Collection<TargetType> filterCollectionByClass(Collection<?> source, final Class<TargetType> clazz) { Collection<?> filtered = Collections2.filter(source, new Predicate<Object>() { @Override public boolean apply(Object input) { return clazz.isInstance(input); } }); return Collections2.transform(filtered, new Function<Object, TargetType>() { @SuppressWarnings("unchecked") @Override public TargetType apply(Object input) { return (TargetType) input; } }); } private  CollectionUtilsExtended(); static Collection<TargetType> filterCollectionByClass(Collection<?> source,
            final Class<TargetType> clazz); static Map<K, List<V>> group(Collection<V> collection, Function<V, K> keyFn);  }
@Test public void testFilterByClass_shouldFilterArrayByInteger() throws Exception { List<Object> example = Arrays.asList(new Object(), 1, 2, 3, "sadf"); Collection<Integer> filtered = CollectionUtilsExtended.filterCollectionByClass(example, Integer.class); assertThat(filtered, hasItems(1, 2, 3)); }