Class Hierarchy
The Array class is present in the java.lang.reflect package, which is part of the java.lang.Object package. The below image represents the hierarchy of the Array class.
java.lang.Object
↳ java.lang.reflect
↳ Class Array

You can also try this code with Online Java Compiler
Run Code
The Arrays class is present in the java.util package, which is part of the java.lang.Object package. The below image represents the hierarchy of the Array class.
java.lang.Object
↳ java.util
↳ Class Arrays

You can also try this code with Online Java Compiler
Run Code
Immutability
The Array class is final, which means that it cannot be altered or even instantiated. The methods contained within this class can be accessed by using the class name.
The Array class cannot be extended or inherited therefore, it is said to be immutable.
The reason for the Array class being immutable is that it is declared final.
The java.util.Arrays class, on the other hand, is not immutable.
Also see, Hashcode Method in Java and Swap Function in Java
Declaration
The class declaration of Array is as follows:
public final class Array extends Object

You can also try this code with Online Java Compiler
Run Code
The class declaration of Arrays is as follows:
public final class Arrays extends Object

You can also try this code with Online Java Compiler
Run Code
Both the Array and Arrays class extend the Object class.
Use
We mostly use the Arrays class in the java.util package when we have to manipulate the array. One of the most common use cases of the Arrays class is when we have to search an element in an array or sort the array.
E.g.: Arrays.sort(array_name);
The Array class in the java.lang.reflect package is a Java reflection class. The Array class includes static methods that can be used to dynamically create and access Java arrays.
E.g: int[] reflectArray = (int[])Array.newInstance(
int.class, arraySize);
One of the biggest advantages of the Array class in the java.lang.reflect package is that it keeps the array to be type-safe.
You can also read about the topic of Java Destructor.
Check out this array problem - Merge 2 Sorted Arrays
Code Demonstration
util.Arrays
// Program to illustrate java.util.Arrays
import java.util.Arrays;
class CodingNinjas {
public static void main(String[] args) {
// create an array
int arr[] = {145, 876, 34, 123, 90, -12, 76};
// using the sort function from the util.Arrays class
Arrays.sort(arr);
// using the binarySearch function from the util.Arrays
// it returns the index of the element which is passed
int idx = Arrays.binarySearch(arr, 34);
// print the sorted array
for (int item : arr) {
System.out.print(item + " ");
}
// for new line
System.out.println();
// print the index of 34
System.out.println("index of 34 in the array is: " + idx);
}
}

You can also try this code with Online Java Compiler
Run Code
Output:
-12 34 76 90 123 145 876
index of 34 in the array is: 1

You can also try this code with Online Java Compiler
Run Code
reflect.Array
// program to demonstrate reflect.Array class
import java.lang.reflect.Array;
public class CodingNinjas {
public static void main(String[] args) {
// we set the size of the array to be 5
int arraySize = 5;
// Create an integer array
// using reflect.Array class
// This is done using the newInstance() method
int[] reflectArray = (int[]) Array.newInstance(
int.class, arraySize);
// using the setInt() method of the reflect.Array
Array.setInt(reflectArray, 0, 10);
Array.setInt(reflectArray, 1, 20);
Array.setInt(reflectArray, 2, 30);
Array.setInt(reflectArray, 3, 40);
Array.setInt(reflectArray, 4, 50);
// right now the array is empty
// by default all the values are zero
for (int item : reflectArray) {
System.out.print(item + " ");
}
}
}

You can also try this code with Online Java Compiler
Run Code
Output:
10 20 30 40 50

You can also try this code with Online Java Compiler
Run Code
Practice it on online java compiler.
FAQs
1.Where is the Arrays class present in Java?
It is present in the java.util package.
2. Where is the Array class present in Java?
It is present in the java.lang.reflect package.
3. Why is the Array class immutable?
The reason for Array class being immutable is that it is declared final.
4. Name some commonly used methods of the Array class in the java.lang.reflect package.
Some commonly used methods of the Array class are Array.newInstance(), Array.set(), Array.get()
5. Name some commonly used methods of the Arrays class in the java.util package.
Some commonly used methods of the Arrays class are Arrays.sort(), Arrays.binarySearch().
Conclusion
In this article, we have extensively discussed util.Arrays vs reflect.Array with code demonstration in Java programming language.
- The Array class in the java.lang.reflect package is a Java reflection class.
- The Arrays class in the java.util package is a Java Collection Framework component.
- Both the Array and Arrays class extend the Object class.
We hope that this blog has helped you enhance your knowledge regarding the reflection array class in Java and if you would like to learn more, check out our articles here.
Recommended problems -
Do upvote our blog to help other ninjas grow. Happy Coding!