I have a java method that should check through an ArrayList and check if it contains an instance of a given class. I need to pass the method the type of class to check for a
You can iterator over your list and test each element
Class> zz = String.class; for (Object obj : list) { if (zz.isInstance(obj)) { System.out.println("Yes it is a string"); } }
Note that isInstance also captures subclasses. Otherwise see Bela`s answer.
isInstance