how to check if a specific 'type of class' is in a list?
Hi all,
I had a similar problem as below but I managed to solve it with an interface. Out of curiosity I wonder how to solve this:
I'm trying to crate a utility class that checks if list contains an instance of a specific class.
I'm not sure what is the 2nd argument I should pass to the method.
example:
List list =new ArrayList();
list.add(new Integer(1));
list.add(new Integer(2));
list.add(new Double(15.35));
list.add("hello there");
.
.
//here, I would like to check if the list contains a String
boolean flag = Utilities.contains(List list, ?);
.
.
.
publicstaticboolean contains(List list, ?)//not sure what to put here (Class clazz?)
{
Iterator itr = list.iterator();
while (itr.hasNext())
{
Criteria c = (Criteria) itr.next();
if (cinstanceof clazz)
returntrue;
}
returnfalse;
}

