Here you can find the source of firstElement(Collection in)
Parameter | Description |
---|---|
in | non-null collection with at least one value |
Parameter | Description |
---|---|
IllegalArgumentException | of the collection is empty |
public static Object firstElement(Collection in)
//package com.java2s; //License from project: Apache License import java.util.*; public class Main { /**//from w w w .j av a 2 s. c om * return the first element in a collection - this is most useful where only one item * exists in the collection * @param in non-null collection with at least one value * @return non-null object * @throws IllegalArgumentException of the collection is empty */ public static Object firstElement(Collection in) { if (in.size() == 0) throw new IllegalArgumentException("firstElement requies at least one entry"); return (in.iterator().next()); } }