- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Determining If an Object Is an Array in Java
In order to determine if an object is an Object is an array in Java, we use the isArray() and getClass() methods.
The isArray() method checks whether the passed argument is an array. It returns a boolean value, either true or false
Syntax - The isArray() method has the following syntax -
Array.isArray(obj)
The getClass() method method returns the runtime class of an object. The getClass() method is a part of the java.lang.Object class.
Declaration − The java.lang.Object.getClass() method is declared as follows −
public final Class getClass()
The getClass() method acts as the intermediate method which returns an runtime class of the object, which enables the terminal method, isArray() to verify it.
Example
Let us see a program to check if an object is an array or not −
public class Example { public static void main(String[] args) throws Exception { String str = "Hello"; String atr[][]= new String[10][20]; System.out.println("Checking for str..."); checkArray(str); System.out.println("Checking for atr..."); checkArray(atr); } public static void checkArray( Object abc) { boolean x = abc.getClass().isArray(); if(x == true) System.out.println("The Object is an Array"); else System.out.println("The Object is not an Array"); } }
Output
Checking for str... The Object is not an Array Checking for atr... The Object is an Array
- Related Articles
- Is an array a primitive type or an object in Java?
- Check if an array object is equal to another array object in C#
- How do we check if an object is an array in Javascript?
- How to convert an object array to an integer array in Java?
- How do I check if an array includes an object in JavaScript?
- how can I declare an Object Array in Java?
- How to create an array of Object in Java
- Check if a value is present in an Array in Java
- Get the Component Type of an Array Object in Java
- Copy all elements in Java TreeSet to an Object Array
- How to convert an object to byte array in java?
- Create an object array from elements of LinkedList in Java
- What is an array in Java?
- How to Check if an Array is Empty or Not in Java
- How to verify if a JavaScript object is an array? Explain with examples.

Advertisements