Java Iterator single(Iterator i)

Here you can find the source of single(Iterator i)

Description

single

License

Apache License

Declaration

public static <T> T single(Iterator<T> i) 

Method Source Code


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

import java.util.Iterator;

public class Main {
    /**//from ww  w  .  j ava 2 s.  c om
     * A single item or null
     *
     * @param iterable The iterable
     * @param <T> The item
     * @return A single item or null
     */
    public static <T> T single(Iterable<T> iterable) {
        Iterator<T> i = iterable.iterator();
        return single(i);
    }

    public static <T> T single(Iterator<T> i) {
        if (i.hasNext()) {
            return i.next();
        }
        return null;
    }
}

Related

  1. removeValue(List args, int idx, Iterator it)
  2. retrieveFirstAndExhaustIterator(Iterator iterator)
  3. safeAdvance(Iterator iterator)
  4. searchIndexInIterator(Iterator iterator, T value)
  5. shallowUnionColIter(Iterator> values)
  6. singleElementIterator(T element)
  7. singleOrDefault(Iterator iterator)
  8. singletonIterator(final Object item)
  9. singletonIterator(final T item)