// Java code to illustrate add(Object o)
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]
程序 2:将 Integer 元素添加到 LinkedList 的集合中。
// Java code to illustrate add(Object o)
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);
}
}