Overview: 1. collection java Collection framework root interface 2. common Sub-interfaces: List, Set, and Queue. Note that map is self-contained. method: [java] package com. cxy. collection; import java. util. arrayList; import java. util. collection; import java. util. hashSet; import java. util. iterator;/*** @ author chenxiaoyang */public class CollectionTest {/*** Note: * 1. collection java Collection framework root interface * 2. common Sub-interfaces: List, Set, and Queue. Note that map is self-contained. System * 3. method: add, include, traverse, intersection, empty, size, empty, etc. */public static void main (String [] args) {Collection children = new ArrayList (); // note that the wildcard type is not added here, so many yellow line warnings // Add children. add ("James"); children. add ("red"); children. add (""); System. out. println ("============================"); // whether the System is included. out. println ("Is there any children named James in kindergarten? A: "+ children. contains (" Xiao Ming "); System. out. println (" Is there any children named Xiao Hei in kindergarten? A: "+ children. contains (""); System. out. println ("============================"); // traverse (two methods) System. out. print ("Iterator method traversal:"); Iterator it = children. iterator (); // Iterator (Iterator) Please refer to the blog article dedicated to iterator while (it. hasNext () {System. out. print (String) it. next () + ""); // because no generic type is used, you need to change it here} System. out. println (""); // keep the format, no practical use/* the above method pays too much attention to the traversal process itself, which is somewhat complicated for beginners, try foreach. * foreach is a convenient Traversal method provided by java 5 */System. o Ut. print ("foreach method traversal:"); for (Object one: children) {System. out. print (String) one + "");} System. out. println (""); // keep the format, no practical use of System. out. println ("===================="); // convert to an array Object [] array = children. toArray (); System. out. println ("array size:" + array. length); System. out. println ("============================"); // Delete the System. out. println ("before deletion:" + children); // This printing method actually uses the toString method of the Collection implementation class children. remove ("James"); System. out. println ("deleted:" + children); System. out. println ("===================="); // intersection Collection goodBoySet = new HashSet (); // a set goodBoySet. add ("James"); goodBoySet. add (""); www.2cto.com children. retainAll (goodBoySet); // The data that exists in the goodBoySet set in the children set. In short, it is the intersection. System. out. println ("intersection Result:" + children); System. out. println ("============================"); // empty, size, and empty System. out. println ("is the set empty? A: "+ children. isEmpty (); System. out. println ("set size:" + children. size (); children. clear (); System. out. println ("is the set empty after being cleared? A: "+ children. isEmpty (); System. out. println ("cleared, set size:" + children. size (); System. out. println ("============================ ");}}