Why does Java allow arrays of size 1? Isn't it useless to wrap one value in an array? Wouldn't it be enough if Java only allowed arrays of size 2 or more?
Yes, we can pass null instead of an empty array and one object or primitive instead of a matrix of size one.
But there are some good arguments against this restriction. My personal main arguments:
The restriction is too complex and not very necessary
To limit the size of arrays to [1..INTEGER.MAX_INT], we would have to add a lot of additional control checks, (agree with Konrads comment), translate the logic and overload method into our code, Exception 0 (and possibly 1) from the allowed sizes array does not save costs, it requires additional effort and adversely affects performance.
Dot matrix vector patterns
An array is a good data model for a vector (mathematics, not the Vector class!). And, of course, the vector in mathematics can be zero. What is conceptually different from nonexistent.
Sidenote - an outstanding wrapper for an array (char -) - is a String class. Immutable String implements the concept of an empty array: it is an empty string ( "" ).
Andreas_D Jan 06 2018-11-11T00: 00Z
source share