// Java code to illustrate clear(Object o)
// of AbstractCollelction
import java.util.*;
import java.util.AbstractCollection;
public class AbstractCollectionDemo {
public static void main(String[] args)
{
// Create an empty Collection
AbstractCollection
输出:
AbstractCollection: [Welcome, To, Geeks, 4, Geeks]
AbstractCollection after using clear: []
方案二:
// Java code to illustrate clear(Object o)
// of AbstractCollelction
import java.util.*;
import java.util.AbstractCollection;
public class AbstractCollectionDemo {
public static void main(String[] args)
{
// Create an empty collection
AbstractCollection
abs = new LinkedList();
// Use add() method to add
// elements in the collection
abs.add(15);
abs.add(20);
abs.add(25);
abs.add(30);
abs.add(35);
// Displaying the Collection
System.out.println("AbstractCollection: "
+ abs);
// Clearing the Collection
abs.clear();
// Displaying the Collection
System.out.println("AbstractCollection "
+ "after using clear: "
+ abs);
}
}
输出:
AbstractCollection: [15, 20, 25, 30, 35]
AbstractCollection after using clear: []