Is an array a primitive type or an object in Java? Last Updated : 11 Dec, 2018 Comments Improve Suggest changes Like Article Like Report An array in Java is an object. Now the question how is this possible? What is the reason behind that? In Java, we can create arrays by using new operator and we know that every object is created using new operator. Hence we can say that array is also an object. Now the question also arises, every time we create an object for a class then what is the class of array? In Java, there is a class for every array type, so there's a class for int[] and similarly for float, double etc. The direct superclass of an array type is Object. Every array type implements the interfaces Cloneable and java.io.Serializable. In the Java programming language, arrays are objects (§4.3.1), are dynamically created, and may be assigned to variables of type Object (§4.3.2). All methods of class Object may be invoked on an array. For every array type corresponding classes are available and these classes are the part of java language and not available to the programmer level. To know the class of any array, we can go with the following approach: // Here x is the name of the array. System.out.println(x.getClass().getName()); Java // Java program to display class of // int array type public class Test { public static void main(String[] args) { int[] x = new int[3]; System.out.println(x.getClass().getName()); } } Output: [I NOTE:[I this is the class for this array, one [ (square bracket) because it is one dimensional and I for integer data type. Here is the table specifying the corresponding class name for some array types:- Array type Corresponding class Name int[] [I int[][] [[I double[] [D double[][] [[D short[] [S byte[] [B boolean[] [Z In Java programming language, arrays are objects which are dynamically created, and may be assigned to variables of type Object. All methods of class Object may be invoked on an array. Java // Java program to check the class of // int array type public class Test { public static void main(String[] args) { // Object is the parent class of all classes // of Java. Here args is the object of String // class. System.out.println(args instanceof Object); int[] arr = new int[2]; // Here arr is also an object of int class. System.out.println(arr instanceof Object); } } Output: true true Reference : https://docs.oracle.com/javase/specs/jls/se7/html/jls-10.html Comment More infoAdvertise with us Next Article Is an array a primitive type or an object in Java? B Bishal Kumar Dubey Improve Article Tags : Misc Java Java-Arrays Java-Array-Programs Practice Tags : JavaMisc Similar Reads Primitive data type vs. Object data type in Java with Examples Data Types in Java Every variable in java has a data type. Data types specify the size and type of values that can be stored in an identifier. Java language is rich in its data types. The variety of data types available allow the programmer to select the type appropriate to the need of the applicati 6 min read How to Find Length or Size of an Array in Java? Finding the length of an array is a very common and basic task in Java programming. Knowing the size of an array is essential so that we can perform certain operations. In this article, we will discuss multiple ways to find the length or size of an array in Java.In this article, we will learn:How to 3 min read How to Return an Array in Java? An array is a data structure that consists of a group of elements of the same data type such that each element of the array can be identified by a single array index or key. The elements of the array are stored in a way that the address of any of the elements can be calculated using the location of 5 min read Array set() method in Java The java.lang.reflect.Array.set() is an inbuilt method in Java and is used to set a specified value to a specified index of a given object array. Syntax Array.set(Object []array, int index, Object value) Parameter : array : This is an array of type Object which is to be updated. index : This is the 3 min read Array setInt() method in Java The java.lang.reflect.Array.setInt() is an inbuilt method in Java and is used to set a specified int value to a specified index of a given object array. Syntax: Array.setInt(Object []array, int index, int value) Parameter: array: This is an array of type Object which is to be updated. index: This is 3 min read Type-Safety and Type-Casting in Java Generics Generics means parameterized types. The idea is to allow type (Integer, String, ⦠etc., and user-defined types) to be a parameter to methods, classes, and interfaces. It is possible to create classes that work with different data types using Generics. An entity such as a class, interface, or method 4 min read util.Arrays vs reflect.Array in Java with Examples Array class in java.lang.reflect package is a part of the Java Reflection. This class provides static methods to create and access Java arrays dynamically. It is a final class, which means it canât be instantiated or changed. Only the methods of this class can be used by the class name itself. On th 2 min read Difference between Stream.of() and Arrays.stream() method in Java Arrays.stream() The stream(T[] array) method of Arrays class in Java, is used to get a Sequential Stream from the array passed as the parameter with its elements. It returns a sequential Stream with the elements of the array, passed as parameter, as its source. Example: Java // Java program to demo 5 min read Why Java Collections Cannot Directly Store Primitives Types? Primitive types are the most basic data types available within the Java language. Such types serve only one purpose â containing pure, simple values of a kind. Since java is a Statically typed language where each variable and expression type is already known at compile-time, thus you can not define 4 min read Array setLong() method in Java The java.lang.reflect.Array.setLong() is an inbuilt method in Java and is used to set a specified long value to a specified index of a given object array. Syntax: Array.setLong(Object []array, int index, long value) Parameter: array : This is an array of type Object which is to be updated. index : T 3 min read Like