I'm new to Java and is learning the concept of array. I have encountered two Java classes: Array and Arrays. I was just wondering what's the difference between the two classes?
They simply serve different purposes with a different set of methods:
The Array class provides static methods to dynamically create and access Java arrays.
This class is essentially a utility class with static methods to manipulate arrays on a lower level. It is usually used for advanced techniques where access to arrays is required through the reflection API.
This class contains various methods for manipulating arrays (such as sorting and searching). This class also contains a static factory that allows arrays to be viewed as lists.
This class is essentially a utility class with static methods to work on raw arrays and to provide a bridge from raw arrays to Collection based arrays (List
).
For example, you can easily fill an array with a particular value:
import java.util.Arrays;
int[] array = new int[1024];
Arrays.fill(array, 42);
Another useful method is toString
which returns a formatted representation of a given array:
System.err.println(Arrays.toString(array));
// [42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, ...]
Array :- This class can be used to create array in run time using reflection.
Arrays :- Utility class,which contains static methods to manipulate(sort,max,min etc.) the values stored in array.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With