Java.lang Package Classes

Java Class - isArray() Method



The java.lang.Class.isArray() method is used to determine if this Class object represents an array class.

Syntax

public boolean isArray()

Parameters

No parameter is required.

Return Value

Returns true if this object represents an array class; false otherwise.

Exception

NA.

Example:

In the example below, the java.lang.Class.isArray() method is used to check whether the given class object is an array class or not.

import java.lang.*;

public class MyClass {
  public static void main(String[] args) {
    //creating class objects
    Integer x = 5;
    int y[] = {10, 20, 30};

    //get class of objects and for array class for x
    Class xcls = x.getClass();
    System.out.println("Is x an array class?: " + xcls.isArray());

    //get class of objects and for array class for y
    Class ycls = y.getClass();
    System.out.println("Is y an array class?: " + ycls.isArray());
  }
}

The output of the above code will be:

Is x an array class?: false
Is y an array class?: true

❮ Java.lang - Class

5