Point to a hashSet


How would I write an if statement that says: if pos2[targetPos3] doesn't point to a hashset (is not a hashset) ? I tried that but it still gives me a null point exception.

Object[] pos2;
int targetPos3;
targetPos3 = word.charAt(2) - 'a';

if(pos2[targetPos3] != (HashSet<String>) pos2[targetPos3]){

Try this:

if(!(pos2[targetPos3] instanceof HashSet)){

There is no way to see if it's a HashSet of String (or any other type for that matter) because of type erasure.