The collection utils used to call next() on an iterator and catch the exception in case there is no next element. This is not optimal, because exceptions are notoriously slow in Java, mainly due to stack trace building. Instead, we should call hasNext().
The collection utils used to call
next()
on an iterator and catch the exception in case there is no next element. This is not optimal, because exceptions are notoriously slow in Java, mainly due to stack trace building. Instead, we should callhasNext()
.