1. Collection Features Overview:
Collection is the top-level interface of a set, and its sub-systems are repetitive, unique, orderly, unordered.
(1) Add function
1 Boolean Add (Object obj): Adds an element 2boolean AddAll (Collection C): Adds an element of a collection
(2) Delete function
1 void Clear (): Remove all elements
(3) Judgment function
1 Boolean contains (Object obj): Determines whether the collection contains the specified element 2boolean containsall (Collection C): Determines whether the collection contains the specified collection element 3boolean isEmpty (): Determines whether the collection is empty
(4) Get function
1 iterator<e> Iterator () (emphasis)
(5) Length function
1 int Size (): The number of collection elements
The Length property in Java is said for an array , for example, you declare an array, and you want to know how long this array is to use this property.
• the length () method in Java is for string literals , and the length () method is used if you want to see how long the string is.
• the size () method in Java is said for a generic collection , and if you want to see how many elements of the generic, call this method to view it!
This example demonstrates the use of both methods and a property
1 Public Static voidMain (string[] args) {2String []list={"Ma", "Cao", "Yuan"};3String a= "Macaoyuan";4 System.out.println (list.length);5 System.out.println (A.length ());6List<object> array=NewArrayList ();7 Array.add (a);8 System.out.println (Array.size ());9}
The output value is:
391
(6) Intersection function
1 boolean retainall (Collection C): intersection of two sets
(7) Convert the set into an array
1 object[] ToArray ()
Java Basic Knowledge Enhancement Collection Framework note 03:collection Collection features overview