Java Collection First getFirst(Collection set, boolean remove)

Here you can find the source of getFirst(Collection set, boolean remove)

Description

get First

License

Open Source License

Declaration

private static <T> T getFirst(Collection<T> set, boolean remove) 

Method Source Code

//package com.java2s;

import java.util.Collection;

import java.util.Iterator;

public class Main {
    private static <T> T getFirst(Collection<T> set, boolean remove) {
        Iterator<T> iterator = set.iterator();
        if (!iterator.hasNext()) {
            throw new IllegalStateException("The set is empty");
        }/*from   w  ww  .j a  va 2  s.co  m*/
        T first = iterator.next();
        if (remove) {
            iterator.remove();
        }
        return first;
    }
}

Related

  1. getFirst(Collection collection)
  2. getFirst(Collection collection)
  3. getFirst(Collection collection)
  4. getFirst(Collection l)
  5. getFirst(Collection set)
  6. getFirst(Collection ts)
  7. getFirst(final Collection collection)
  8. getFirstAndOnly(Collection c)
  9. getFirstClassOfType(Collection l, Class type)