Java Collection First first(Collection collection, E alternative)

Here you can find the source of first(Collection collection, E alternative)

Description

first

License

Apache License

Declaration

public static <E> E first(Collection<? extends E> collection, E alternative) 

Method Source Code


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

import java.util.Collection;
import java.util.Iterator;

public class Main {
    public static <E> E first(Collection<? extends E> collection, E alternative) {
        Iterator<? extends E> iterator = collection.iterator();
        if (iterator.hasNext()) {
            return iterator.next();
        }/*from   www  . j a  v a 2s.co m*/
        return alternative;
    }
}

Related

  1. first(Collection collection)
  2. first(Collection collection)
  3. first(Collection items)
  4. first(Collection collection)
  5. first(Collection collection)
  6. first(Collection values)
  7. first(Collection collection)