Java Iterator singleOrDefault(Iterator iterator)

Here you can find the source of singleOrDefault(Iterator iterator)

Description

single Or Default

License

BSD License

Declaration

public static <T> T singleOrDefault(Iterator<T> iterator) 

Method Source Code

//package com.java2s;
//License from project: BSD License 

import java.util.Iterator;

public class Main {
    public static <T> T singleOrDefault(Iterator<T> iterator) {
        if (!iterator.hasNext()) {
            return null;
        }//from www.  j a  v a2  s.  c o m
        T first = iterator.next();
        if (iterator.hasNext()) {
            throw new IllegalStateException("Expected single result, but got more than one");
        }
        return first;
    }
}

Related

  1. safeAdvance(Iterator iterator)
  2. searchIndexInIterator(Iterator iterator, T value)
  3. shallowUnionColIter(Iterator> values)
  4. single(Iterator i)
  5. singleElementIterator(T element)
  6. singletonIterator(final Object item)
  7. singletonIterator(final T item)
  8. singletonIterator(final T nullableValue)
  9. singletonIterator(final T t)