Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Java, why is the class "Arrays" plural? [closed]

Tags:

java

arrays

In Java, you import HashMap; and import ArrayList;, etc. So why is import Arrays; plural?

like image 693
jds Avatar asked Nov 15 '14 22:11

jds


3 Answers

The Utility classes which deals with Arrays, Files, Paths, Objects or Collections are plural. Exactly because they are not an Array or a Collection but rather a number of utility functions to work on them. You can even see that in the Javadoc intro:

This class contains various methods for manipulating arrays

Some of those classes are fairly new additions in 1.7. So this explains their common naming convention. I am not sure if there is a written conventions for it, but it is surely a practical one.

like image 61
eckes Avatar answered Nov 08 '22 13:11

eckes


Because it's a collection of utilities to work with arrays. The other examples you've mentioned are actually instances of a particular type of collection.

For example, the same naming convention has been followed in Guava for Lists, Sets, Maps etc.

like image 28
Alex Ciminian Avatar answered Nov 08 '22 13:11

Alex Ciminian


It is a collection of utilities that deals with arrays, and doesn't represent the array itself. Also there is another class with name Array. Check this https://docs.oracle.com/javase/7/docs/api/java/lang/reflect/Array.html

like image 4
Mubin Avatar answered Nov 08 '22 11:11

Mubin