Java Class.isArray()

Syntax

Class.isArray() has the following syntax.

public boolean isArray()

Example

In the following code shows how to use Class.isArray() method.


//from   www.  ja v  a2 s .  c om
import java.lang.reflect.Array;

public class Main {

   public static void main(String[] args) {

     String str = "This is from java2s.com";

     Class cls = str.getClass();
     boolean arr = cls.isArray();
     System.out.println(arr);
     
     
     Object array = Array.newInstance(int.class, 3);
    
     Class type = array.getClass();
     if (type.isArray()) {
       Class elementType = type.getComponentType();
       System.out.println("Array of: " + elementType);
       System.out.println("Array size: " + Array.getLength(array));
     }
   }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    java.lang »




Boolean
Byte
Character
Class
Double
Enum
Float
Integer
Long
Math
Number
Object
Package
Process
ProcessBuilder
Runnable
Runtime
SecurityManager
Short
StackTraceElement
StrictMath
String
StringBuffer
StringBuilder
System
Thread
ThreadGroup
ThreadLocal
Throwable