Java Iterable Item getFirst(Iterable iterable)

Here you can find the source of getFirst(Iterable iterable)

Description

get First

License

Open Source License

Declaration

public static <T> T getFirst(Iterable<T> iterable) 

Method Source Code

//package com.java2s;
/*//  w ww.j a  v  a2  s  .  co m
 * Copyright Siemens AG, 2014-2016.
 * With modifications by Bosch Software Innovations GmbH, 2016
 * Part of the SW360 Portal Project.
 *
 * SPDX-License-Identifier: EPL-1.0
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 */

import java.util.*;

public class Main {
    public static <T> T getFirst(Iterable<T> iterable) {
        final Iterator<T> iterator = iterable.iterator();
        if (iterator.hasNext()) {
            return iterator.next();
        } else {
            throw new NoSuchElementException();
        }
    }
}

Related

  1. concat(final Iterable> iterables)
  2. concat(Iterable... iterables)
  3. concat(Iterable first, Iterable second)
  4. contains(Iterable iter, Object o)
  5. getFirst(final Iterable iterable)
  6. getFirstElement(Object maybeIterable)
  7. getFrom(Iterable iterable, int index)
  8. isIterable(Object obj)
  9. isPrefix(Iterable suspectedPrefix, Iterable container)