public static Iterator < Node > iterator ( final NodeList nodeList ) { return new Iterator < Node > ( ) { private int current /* = 0 */ ; public boolean hasNext ( ) { return current < nodeList . getLength ( ) ; } public Node next ( ) { return nodeList . item ( current ++ ) ; } public void remove ( ) { throw new UnsupportedOperationException ( "Cannot remove() from a NodeList iterator" ) ; } } ; }
Makes NodeList iterable by returning a read - only Iterator which traverses over each Node .