Annibigi
Annibigi

Reputation: 6045

How to verify if variable type is an array in Java languge

I'm new to java. Please let me know how to verify if variable type is an array in Java languge.

Upvotes: 1

Views: 153

Answers (2)

Shawn D.
Shawn D.

Reputation: 8125

With any object, you can do this:

Class clazz = myObject.getClass();

if( clazz.isArray() ) {
    // ... array specific stuff.
}

Upvotes: 7

Chris Dennett
Chris Dennett

Reputation: 22721

Any type that is suffixed by [] is an array type.

Upvotes: 1

Related Questions