Finding Out of what Class an Object is Instantiated
import java.util.ArrayList;
import java.util.Vector;
public class Main {
public static void main(String[] args) {
Object testObject = new Vector();
if (testObject instanceof Vector)
System.out.println("Object was an instance of the class java.util.Vector");
else if (testObject instanceof ArrayList)
System.out.println("Object was an instance of the class java.util.ArrayList");
else
System.out.println("Object was an instance of the " + testObject.getClass());
}
}
//Object was an instance of the class java.util.Vector
Related examples in the same category