Here you can find the source of getFirstElement(Object maybeIterable)
Parameter | Description |
---|---|
maybeIterable | a parameter |
public static Object getFirstElement(Object maybeIterable)
//package com.java2s; //License from project: Apache License import java.util.Iterator; public class Main { /**//from w w w . j av a2 s. co m * Returns the first element, if any, of an object that may be an {@link Iterable} * * @param maybeIterable * @return */ public static Object getFirstElement(Object maybeIterable) { if (!(maybeIterable instanceof Iterable<?>)) return null; Iterable<?> iterable = (Iterable<?>) maybeIterable; Iterator<?> iterator = iterable.iterator(); return iterator.hasNext() ? iterator.next() : null; } }