Here you can find the source of getIdenticalElement(Iterable
public static <T> T getIdenticalElement(Iterable<T> iterable)
//package com.java2s; //License from project: Open Source License import java.util.Iterator; public class Main { /**/* w w w.j ava 2 s . co m*/ * @see JavaHelper#getIdenticalElement(Iterator) */ public static <T> T getIdenticalElement(Iterable<T> iterable) { return getIdenticalElement(iterable.iterator()); } /** * If all elements in the iterator are (equal-)identical, return the element * (the first). Else return <code>null</code>. */ public static <T> T getIdenticalElement(Iterator<T> iterator) { if (!iterator.hasNext()) { return null; } final T result = iterator.next(); while (iterator.hasNext()) { T next = iterator.next(); if (!result.equals(next)) { return null; } } return result; } }