Here you can find the source of singletonIterator(final T nullableValue)
public static <T> Iterator<T> singletonIterator(final T nullableValue)
//package com.java2s; //License from project: Apache License import java.util.Iterator; import java.util.NoSuchElementException; public class Main { private static final Iterator<Object> EMPTY_ITERATOR = new Iterator<Object>() { @Override/*w w w . j a v a 2 s . com*/ public boolean hasNext() { return false; } @Override public Object next() { throw new NoSuchElementException(); } @Override public void remove() { throw new UnsupportedOperationException("remove"); } }; public static <T> Iterator<T> singletonIterator(final T nullableValue) { if (nullableValue == null) { return (Iterator<T>) EMPTY_ITERATOR; } return new Iterator<T>() { boolean done; @Override public boolean hasNext() { return !done; } @Override public T next() { if (done) { throw new NoSuchElementException(); } done = true; return nullableValue; } @Override public void remove() { throw new UnsupportedOperationException("remove"); } }; } }