Here you can find the source of getFirst(Collection
Parameter | Description |
---|---|
collection | a parameter |
public static String getFirst(Collection<String> collection)
//package com.java2s; import java.util.Collection; import java.util.Iterator; public class Main { /**/*w w w. j a va2 s. c om*/ * Utility function to get a sample item from a collection * * @param collection * @return the first item from the collection, or null if the collection is * empty */ public static String getFirst(Collection<String> collection) { Iterator<String> it = collection.iterator(); if (it.hasNext()) { return it.next(); } return null; } }