Common method 1 of Collection: collection
Import java. util. *; public class CollectionTest {public static void main (String [] args) {Collection C = new ArrayList (); // create an ArratList set C. add (1); // The set can only contain reference data. C. add (new Integer (100); Object o = new Object (); C. add (o); // storage reference type, which is a memory address: Customer cus = new Customer ("Zhang San", 24); C. add (cuz); System. out. println ("the number of elements in the set is:" + C. size () + ", whether the set is empty:" + C. isEmpty (); Object O [] = C. toArray (); // converts a set into an array for (int I = 0; I <O. length; I ++) {System. out. println (the "+ I +" element of the set is: "+ O [I]);} C. clear (); System. out. println ("the number of elements in the set is:" + C. size () + ", whether the set is empty:" + C. isEmpty () ;}} class Customer {String name; int age; Customer (String name, int age) {this. name = name; this. age = age;} public String toString () {return "name [" + this. name + "], age [" + this. age + "]";}}