Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javadoc of ArrayUtils.isNotEmpty is faulty?

The javadoc of ArrayUtils.isNotEmpty() in Apache Commons Lang seems to be wrong. Or, at least, misleading. It says

Returns: true if the array is not empty or not null

In my understanding, an empty array is not null. So, according to the above definition, isNotEmpty() should return true for an empty array, which is counterintuitive.

Wouldn't

Returns: true if the array is not null and not empty

be more correct?

like image 798
Ulrich Scholz Avatar asked Jan 21 '14 09:01

Ulrich Scholz


People also ask

Is Arrayutils deprecated?

Deprecated. this method has been superseded by insert(int, boolean[], boolean...) and may be removed in a future release.

What is array utils in Java?

The Arrays class in java. util package is a part of the Java Collection Framework. This class provides static methods to dynamically create and access Java arrays. It consists of only static methods and the methods of Object class. The methods of this class can be used by the class name itself.


1 Answers

Wouldn't

Returns: true if the array is not null and not empty

be more correct?

Yes you are right. The doc is a bit misleading. In fact, if you see the source code, it does exactly that:

public static boolean isNotEmpty(Object[] array) {
   return (array != null && array.length != 0);
}
like image 66
Rohit Jain Avatar answered Sep 21 '22 00:09

Rohit Jain