Set features: Containers used to store objects (reference of stored objects). The length of the set is variable, and basic data type values cannot be stored in the set.
Differences between a set and an array:
Can store any object in the collection, and the length is variable
The array can only store data of the same type, and the length is immutable.
Common methods of Collection:
Add element boolean add (Object );
ArrayList a1 = a1.add("java01" a1.add("java02" a1.add("java03" a1.add("java04" System.out.println(a1); }
Delete the boolean remove (Object) element. The returned value is boolean. (You can delete an Object using the specified badge in the List set. The returned value is the deleted Object)
ArrayList a1 = a1.add("java01" a1.add("java02" a1.add("java03" a1.add("java04" b = a1.remove("java03" }
Clear element: void clear (); this exception is thrown if the set does not support this method: UnsupportedOperationException
ArrayList a1 = a1.add("java01" a1.add("java02" a1.add("java03" a1.add("java04" }
Determine whether an element exists: boolean contains (Object)
ArrayList a1 = a1.add ("java01" a1.add ("java02" a1.add ("java03" a1.add ("java04" B = a1.contains ("java03" System. out. println ("Does java03 exist:" +}
Get the number of elements in the Set: int size ();
ArrayList a1 = a1.add("java01" a1.add("java02" a1.add("java03" a1.add("java04" a = System.out.println("size:"+ }
Determines whether the set is empty: boolean isEmpty ();
ArrayList a1 = a1.add ("java01" a1.add ("java02" a1.add ("java03" a1.add ("java04" B = System. out. println ("is the set empty? : "+}
Intersection: al1 retains only the same elements as al2. if there is no intersection, It is null: boolean retainAll (Object)
ArrayList al1 = al1.add("java01" al1.add("java02" al1.add("java03" al1.add("java04" ArrayList al2 = al2.add("java01" al2.add("java02" al2.add("java05" al2.add("java06" b = al1.removeAll(al2); }
Special method Iterator: retrieves the element in the Set: iterator <e> Iterator (); (an Iterator interface is returned)
Methods In the Iterator interface:
There are no elements to judge: boolean hasNext ()
Next element of iteration: E next ();
Delete element: void remove ()
ArrayList al = al.add("java01" al.add("java02" al.add("java03" al.add("java04" Iterator it = }