public static < T > Iterator < T > singleElementIterator ( final T element ) { return new Iterator < T > ( ) { private boolean mHasNext = true ; @ Override public boolean hasNext ( ) { return mHasNext ; } @ Override public T next ( ) { if ( ! hasNext ( ) ) { throw new NoSuchElementException ( ) ; } mHasNext = false ; return element ; } @ Override public void remove ( ) { throw new UnsupportedOperationException ( "remove is not supported." ) ; } } ; }
Returns an iterator that iterates on a single element .