Java examples for java.util:Iterable Element
get Single Element Of Iterable
//package com.java2s; import java.util.Iterator; public class Main { public static <T> T getSingleElementOf(Iterable<T> iterable) { Iterator<T> iterator = iterable.iterator(); T first = iterator.next();/* w w w . ja v a 2 s. co m*/ if (iterator.hasNext()) throw new IllegalArgumentException( "Expected only a single element in " + iterable); return first; } }