How to check if the object given to me is int [] in Java?

How to check if a given int[] object matches me in Java?

+4
source share
4 answers

How do you expect:

 if (theObject instanceof int[]) { // use it! } 

Arrays of Objects , even if they are arrays of primitives.

+22
source
 if (o instanceof int[]) { ... } 

Arrays are objects in java.

+1
source

Get the execution class of a variable if it is one dimensional array, the class name is like [int, if it is a 2-dimensional array, class name [[int and if it is a three-dimensional class name [[[int

 if ( j.class.Name.equals("[int")) { ...... } 
0
source

intanceof is simple, but do literally what you ask.

 if (o.getClass() == int[].class) 
0
source

All Articles