Java Iterable Item clear(Iterable iterable)

Here you can find the source of clear(Iterable iterable)

Description

Remove all elements from the given Iterable.

License

LGPL

Parameter

Parameter Description
iterable the Iterable

Declaration

public static void clear(Iterable<?> iterable) 

Method Source Code

//package com.java2s;
//License from project: LGPL 

import java.util.*;

public class Main {
    /**//w  w w  .  j  a v a2  s.  c o m
     * <p>Remove all elements from the given Iterable.</p>
     * @param iterable the Iterable
     */
    public static void clear(Iterable<?> iterable) {
        if (iterable instanceof Collection) {
            ((Collection<?>) iterable).clear();
        } else {
            clear(iterable.iterator());
        }
    }

    /**
     * <p>Remove all elements from the given Iterator.</p>
     * @param it the Iterator
     */
    public static void clear(Iterator<?> it) {
        while (it.hasNext()) {
            it.next();
            it.remove();
        }
    }
}

Related

  1. concat(final Iterable> iterables)
  2. concat(Iterable... iterables)
  3. concat(Iterable first, Iterable second)
  4. contains(Iterable iter, Object o)