Collection frame: Collection
Why are there so many containers?
Because each container has a different way of storing the data,
This storage method is called: Data structure
Collectiondemo
Creates a collection container. Using subclasses of the collection interface, ArrayList
/*
The parameter type of the 1,add method is object. To facilitate acceptance of any type of object.
2, the object's reference (address) is stored in the collection
*/
Import java.util.*;classcollectiondemo{ Public Static voidMain (string[] args) {Base_method (); } Public Static voidBase_method () {//ArrayList al = new ArrayList (); //1, adding elements//Al.add ("Java01"); //Al.add ("java02"); //Al.add ("java03"); //Al.add ("Java04"); //Print Original Collection//SOP ("SCR:" +al); //Clear//al.clear (); //al.remove ("java02"); //gets the number of elements, set length. //SOP ("Size:" +al.size ()); //System.out.println (""); //determine if an element exists//SOP (Al.contains ("java03")); //SOP (Al.isempty ());//whether the collection is empty. SOP (AL); ArrayList Al=NewArrayList (); Al.add ("JAVA01"); Al.add ("JAVA02"); Al.add ("java03"); Al.add ("java04"); ArrayList All=NewArrayList (); All.add ("java05"); All.add ("java06"); All.add ("JAVA01"); All.add ("JAVA02"); Al.retainall (all);//, Al will only be saved in the same element in all. SOP ("al:"+al); SOP ("All :"+All ); } Public Static voidsop (Object obj) {System. out. println (obj); }}
DAY14 Collection Frame--arraylist container