public static < T > Iterator < T > checkHasNext ( Iterator < T > iterator , String message ) throws NoSuchElementException { if ( ! iterator . hasNext ( ) ) { throw new NoSuchElementException ( message ) ; } return iterator ; }
Check if iterator has next element . If not throw NoSuchElementException