Java.lang.Class.isArray() Method


Advertisements


Description

The java.lang.Class.isArray() determines if this Class object represents an array class.

Declaration

Following is the declaration for java.lang.Class.isArray() method

public boolean isArray()

Parameters

NA

Return Value

This method returns true if this object represents an array class, else false.

Exception

NA

Example

The following example shows the usage of java.lang.Class.isArray() method.

package com.tutorialspoint;

import java.lang.*;

public class ClassDemo {

   public static void main(String[] args) {

      String str = "This is TutorialsPoint";

      // returns true if this object represents an array class, else false
      Class cls = str.getClass();
      
      // checking for array
      boolean arr = cls.isArray();
      if(arr) {
         System.out.println("Result : " + cls.getName() + " is an array");
      } else {
         System.out.println("Result : " + cls.getName() + " is not an array");
      }
   }
} 

Let us compile and run the above program, this will produce the following result −

Result : java.lang.String is not an array

java_lang_class.htm

Advertisements