Here you can find the source of getAny(final Collection
Parameter | Description |
---|---|
collection | to retrieve the element from |
public static <T> T getAny(final Collection<T> collection)
//package com.java2s; //License from project: Apache License import java.util.Collection; import java.util.Iterator; public class Main { /**/*from www .jav a2s. c o m*/ * Returns an arbitrary element from the given collection. * * @param collection * to retrieve the element from * @return an arbitrary element or <tt>null</tt> if the collection is empty */ public static <T> T getAny(final Collection<T> collection) { final Iterator<T> iterator = collection.iterator(); if (iterator.hasNext()) { return iterator.next(); } return null; } }