Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why we have Arrays and Array in Java

Tags:

java

arrays

I have run into these two documentations:

  • Java documentation for the class Array
  • Java documentation for the class Arrays

and I'm wondering what the difference is between these two classes. They both provide a different set of static methods, but why are they separate? What is the deeper difference? And what is the relation between them and with the normal instance of array like int[].

I notice that they are from totally different packages, but still hope to find some clarification. Thanks.

like image 715
Yuqing Avatar asked Dec 10 '22 18:12

Yuqing


1 Answers

The differences are made fairly clear in the docs.

From Arrays.java:

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.

From Array.java

The Array class provides static methods to dynamically create and access Java arrays.

Essentialy Array is an implementation of core Array operations - getting, setting and instantiation.

Arrays is a helper class for wrapping common Array operations (conversion between Arrays and Lists, sorting, searching for a value) without polluting the core Array "api".

like image 140
Nathaniel D. Waggoner Avatar answered Dec 29 '22 19:12

Nathaniel D. Waggoner