A comparison of sets and arrays
Using an array to store objects has some drawbacks, and the Java collection is like a container that dynamically puts references to multiple objects in a container.
The disadvantage of an array: Once the length is set, it cannot be changed, and the number of elements in the array is unknown.
Ii. Overview of the collection
|--- Collection Collection
|---List interface: ordered, repeatable sequence.
|---ArrayList collection (the main manifestation of list)
|---linkedlist
|---Vector
|---Set interface: unordered, non-repeatable.
|---TreeSet
|---HashSet
|---Map collection: Key-->value Key-value pairs
Iii. Common methods of collection
1.size (): Returns the number of collection elements 2.add (): Adds a new element to the collection /span>3.addall (): Copies the elements in the parameter collection to the current collection 4 5 6, Contains (Object obj): Determines whether the collection contains the obj element 7 8, Retainall (): Takes the intersection of the current collection and the parameter collection, and leaves it to the current collection 9, Remove (Object obj): Deletes the first occurrence of obj in the current collection, 10 11 12, ToArray (): Converts the current combination into an array 13 14, iterator (): Returns an object of the iterator interface implementation class.
Collection Common Methods list
Note: You must override the Equals () method if you are comparing objects for equality when you add custom types to the collection.
Iv. Traversal of a collection
(1) for (int)
(2) Enhanced for ()
(3) iterator Iterator,hasnext (), Next ().
V. List
Features: Ordered and repeatable code.
Common methods:
(1) void Add (int index,object obj);
(2) Boolean addall (int index,collection coll);
(3) Object get (int index);
(4) int indexOf (Object obj);
(5) int lastof (Object obj);
(6) Object Remove (int index);
(7) Object set (int index,object obj);
(8) List sublist (int fromindex,int toindex);
Vi. Collection Frame Structure
The picture is slightly ugly ah, hahaha, today for everyone to update the contents of the collection, if you feel that it helps, please order to praise it!!!
Java Collection Framework