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.*; public class Main { /**//from w ww . jav a 2 s . com * 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; } }