Here you can find the source of clear(Iterable> iterable)
Remove all elements from the given Iterable.
Parameter | Description |
---|---|
iterable | the Iterable |
public static void clear(Iterable<?> iterable)
//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(); } } }