Example:
Object[] x = new Object[2];
x[0] = 3;
x[1] = "4";
System.out.println(x[0].getClass().getSimpleName());
System.out.println(x[1].getClass().getSimpleName());
This makes me wonder: is the first element of the object an instance of the class Integer? or is it a primitive data type int? There is a difference, right?
So, if I want to determine the type of the first element (this is an integer, double, string, etc.), how to do it? Do I use x[0].getClass().isInstance()? (if so, how?), or am I using something else?
source
share