You can iterate over the list and test each item
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 Bel's answer.
source share