Java Utililty Methods Iterable

List of utility methods to do Iterable

Description

The list of methods to do Iterable are organized into topic(s).

Method

booleanisEmpty(Iterable i)
is Empty
return !i.iterator().hasNext();
Iterableiterable(final Iterable in)
iterable
return new Iterable<T>() {
    @Override
    public Iterator<T> iterator() {
        return in.iterator();
};
doublemax(Iterable iterable)
max
Iterator<Double> iterator = iterable.iterator();
double max = Double.MIN_VALUE;
while (iterator.hasNext()) {
    double d = iterator.next();
    if (d > max) {
        max = d;
return max;
IterablemergeConsecutiveTokens(Iterable tokens)
merge Consecutive Tokens
return new Iterable<String>() {
    @Override
    public Iterator<String> iterator() {
        final Iterator<String> token_iter = tokens.iterator();
        return new Iterator<String>() {
            Iterator<String> iter = token_iter;
            String _last_token = null;
            String _token;
...
StringprettyPrintComma(Iterable a)
pretty Print Comma
String res = "";
if (a == null) {
    return res;
Iterator<Object> it = a.iterator();
if (it.hasNext()) {
    res += it.next();
while (it.hasNext()) {
    res += ",";
    res += it.next();
return res;
DataTyperemoveElement(final Iterable iterable, int index)
Removes and returns the indexed value into the Iterable .
if (iterable instanceof List<?>) {
    return ((List<DataType>) iterable).remove(index);
} else {
    if (index < 0) {
        throw new IndexOutOfBoundsException("index must be >= 0");
    Iterator<DataType> iterator = iterable.iterator();
    while (iterator.hasNext()) {
...
booleanremoveIgnoreCase(Iterable haystack, String needle)
Remove the first occurrence of needle (ignoring case)
Iterator<String> iterator = haystack.iterator();
while (iterator.hasNext()) {
    String string = iterator.next();
    if (needle.equalsIgnoreCase(string)) {
        iterator.remove();
        return true;
return false;
TsecondOf(final Iterable iterable)
second Of
return nthOf(iterable, 1);
booleansequenceEqual(Iterable one, Iterable two)
Compares two sequences of values and returns true if sequence members are equal and in the same order
Iterator<T> iter1 = one.iterator();
Iterator<T> iter2 = two.iterator();
while (iter1.hasNext() && iter2.hasNext()) {
    if (iter1.next() != iter2.next()) {
        return false;
return (!iter1.hasNext() && !iter2.hasNext());
...
ListshallowCopy(Iterable ori)
Generates a new Iterable that references the items of the given Iterable .
ArrayList<T> copy = new ArrayList<T>();
for (T t : ori) {
    copy.add(t);
return copy;