- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
Get the Component Type of an Array Object in Java
In order to get the component type of an Array Object in Java, we use the getComponentType() method. The getComponentType() method returns the Class denoting the component type of an array. If the class is not an array class this method returns null.
Declaration − The java.lang.Class.getComponentType() method is declared as follows -
public Class<?> getComponentType()
Let us see a program to the get the component type of an Array Object in Java -
Example
public class Example { public static void main(String[] args) { int[] array = new int[] {1,2,3}; // obtain the Class of the component type Class arrayClass = array.getClass(); // obtaining the component type Class component = arrayClass.getComponentType(); if (component != null) { System.out.println("Component type is " + component.getName()); } else { System.out.println("Component type is null"); } } }
Output
Component type is int
- Related Articles
- Is an array a primitive type or an object in Java?
- Get super class of an object in Java
- Filter the properties of an object based on an array and get the filtered object JavaScript
- Get class from an object in Java
- Get the path of the file selected in the JFileChooser component with Java
- Can you create an array of Generics type in Java?
- How to create an array of Object in Java
- Determining If an Object Is an Array in Java
- Create an object array from elements of LinkedList in Java
- How to convert an object array to an integer array in Java?
- Get the name of a primitive type in Java
- How to get items from an object array in MongoDB?
- Get the Most Frequent Element in an Array in Java
- Get the handle for the Type of a specified object C#
- Is String a primitive data type or an object in Java?

Advertisements