Skip to content

Instantly share code, notes, and snippets.

@valbaca
Created June 2, 2022 05:15
Show Gist options
  • Save valbaca/bba15599e36eda70c2c8ae34281c21d0 to your computer and use it in GitHub Desktop.
Save valbaca/bba15599e36eda70c2c8ae34281c21d0 to your computer and use it in GitHub Desktop.
package com.valbaca;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
public class Gens {
public static void main(String[] args) {
List<Class> classes = new ArrayList<>();
classes.add(String.class);
classes.add(Date.class);
List things = new ArrayList();
things.add("foo");
things.add(new Date());
for (Class clazz : classes) {
List list = new ArrayList();
for (Object something : things) {
if (clazz.isInstance(something)) list.add(something);
}
System.out.print(clazz.getSimpleName());
System.out.print(list);
System.out.println();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment