I have an array of objects (Object[] array), and I want to check whether it is empty, but fail fast if it is null with NPE or any other exception.
I know that I can do the following check
array.length == 0
but e.g. in case of String or collections it is not recommended practice, IntelliJ even has inspection for that:
Reports any
.size()or.length()comparisons with a 0 literal which can be replaced with a call to.isEmpty().
Is there any replacement for .isEmpty() for arrays?
There is ArrayUtils.html#isEmpty(java.lang.Object[]), but it also checks for null, while I'd like to avoid that.
array.length == 0and ignore intellijs useless tip, because isEmpty() obviously doesn't do what you want. be sure to check for null first