In Java, why is the Arrays class plural?

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

+5
source share
5 answers

Utility classes that deal with Arrays , Files , Paths , Objects or Collections are plural. Precisely because they are not an array or collection, but represent a series of useful functions for working on them. You can even see that in the Javadoc intro:

This class contains various array management methods.

Some of these classes are fairly new additions to 1.7. Thus, this explains their general naming convention. I am not sure if there are written agreements for this, but it is certainly practical.

+12
source

Because it is a set of utilities for working with arrays. The other examples you mentioned are actually instances of a particular type of collection.

For example, Guava maintained the same naming convention for lists, sets, maps, etc.

+4
source

This is a collection of utilities that deals with arrays and is not an array. There is also another class called Array . Check out https://docs.oracle.com/javase/7/docs/api/java/lang/reflect/Array.html

+3
source

This is for transforming author and code, how to name classes.

+3
source

HashMap, ArrayList, etc. are objects. They are data structures that offer different functions and have different uses.

Arrays (or Collections ), on the other hand, is not an object. Arrays are a class that contains only static utilities that can perform convenient operations on arrays.

+2
source

Source: https://habr.com/ru/post/1206962/


All Articles