Cells.getEnumerator() vs Cells.getRows().iterator()

Prior to 7.0 we used Cells.getRowIterator() to process rows. That seems to have been replaced with Cells.getEnumerator(), but when I use that I get no rows returned.

Iterator rowIterator = cells.getRowEnumerator();
Row headerRow = rowIterator.next(); // this return NULL

Iterator rowIterator = cells.getRows().iterator();

Row headerRow = rowIterator.next(); // this returns the valid Row.




Should we not be using getRowEnumerator? Or does it do something different that I’m expecting?

Hi,

Please use worksheet.getCells().getRows() collection to process rows.

Hi,


It is because of the different implementations for returned Iterator. For the iterator you got by “cells.getRowEnumerator()”, you need to call iter.hasNext() before every calling of iter.next(). So when you call iter.next() directly without checking with iter.hasNext(), null will be returned. However, it is not required for the iterator got by RowCollection.iterator(). Anyways, for a common Iterator, we think it is always a better practice to check iter.hasNext() before iter.next() because iter.next() will give exception when there is no more element in the collection.

Thank you.