Finding Out of what Class an Object is Instantiated : instanceof « Operators « Java Tutorial






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








3.10.instanceof
3.10.1.The instanceof Keyword
3.10.2.Identifying Objects
3.10.3.Finding Out of what Class an Object is Instantiated
3.10.4.instanceof operator and class hierarchy