Java Utililty Methods Iterable Item

List of utility methods to do Iterable Item

Description

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

Method

voidclear(Iterable iterable)

Remove all elements from the given Iterable.

if (iterable instanceof Collection) {
    ((Collection<?>) iterable).clear();
} else {
    clear(iterable.iterator());
Iterableconcat(final Iterable> iterables)
concat
return new Iterable<T>() {
    @Override
    public Iterator<T> iterator() {
        return new Iterator<T>() {
            private final Iterator<? extends Iterable<T>> iterablesIterator = iterables.iterator();
            private Iterator<T> currentIterator = iterablesIterator.hasNext()
                    ? iterablesIterator.next().iterator()
                    : null;
...
Iterableconcat(Iterable... iterables)
concat
return concat(Arrays.asList(iterables));
Iterableconcat(Iterable first, Iterable second)
concat
return new Iterable<T>() {
    final Iterator<T> it1 = first.iterator();
    final Iterator<T> it2 = second.iterator();
    @Override
    public Iterator<T> iterator() {
        return new Iterator<T>() {
            Iterator<T> curr;
            @Override
...
booleancontains(Iterable iter, Object o)
Test whether the given object appears in an iteration of iter .
if (iter instanceof Collection<?>) {
    return ((Collection<?>) iter).contains(o);
} else {
    return iteratedContains(iter, o);
EgetFirst(final Iterable iterable)
Retrieves the first element of an Iterable
final Iterator<E> iter = iterator(iterable);
return hasNext(iter) ? iter.next() : null;
TgetFirst(Iterable iterable)
get First
final Iterator<T> iterator = iterable.iterator();
if (iterator.hasNext()) {
    return iterator.next();
} else {
    throw new NoSuchElementException();
ObjectgetFirstElement(Object maybeIterable)
Returns the first element, if any, of an object that may be an Iterable
if (!(maybeIterable instanceof Iterable<?>))
    return null;
Iterable<?> iterable = (Iterable<?>) maybeIterable;
Iterator<?> iterator = iterable.iterator();
return iterator.hasNext() ? iterator.next() : null;
TgetFrom(Iterable iterable, int index)
get From
if (iterable instanceof List<?>) {
    return (T) ((List<?>) iterable).get(index);
return elementAt(iterable, index);
booleanisIterable(Object obj)
is Iterable
return obj.getClass().isArray() || (obj instanceof Class<?> && ((Class<?>) obj).isArray())
        || obj instanceof Iterable || obj instanceof Enumeration;