-
The difference between a collection and an array
1) The difference in length:
Array: Length is fixed
Set: Length is variable
2) Differences in storage data types:
Arrays: You can store basic data types and can also store reference data types
Collection: Only reference types can be stored
3) The difference between the elements of the storage type:
Collection: Stores multiple types of elements: Water + Cola + beer ...
Arrays: Elements that are stored in the same data type: Water in a water cup
-
The root interface in the Collection hierarchy.
Collection represents a set of objects, also known as Collection elements. Some collection allow duplicate elements, while others do not. Some of the collection are orderly, while others are unordered.
The JDK does not provide any direct implementation of this interface: it provides more specific sub-interfaces (such as Set and List) implementations.
The basic method of 3.Collection:
Boolean AddAll (Collection C): Add an element from a collection
Boolean RemoveAll (Collection c): Delete an element in a collection (think: Delete an element is deleted or delete all is deleted?)
Boolean containsall (Collection C): Determines whether an element in a collection is included (contains a count, or contains all the elements of an arithmetic inclusion?)
Intersection function:
Boolean retainall (Collection C): Intersection of a set (think: What does the return value type mean? Where do the elements of the intersection go?)
650) this.width=650; "Title=" collection 1.png "src=" https://s3.51cto.com/wyfs02/M00/9D/C6/ Wkiol1mfudkyoalcaaecsqdgl7e509.png-wh_500x0-wm_3-wmp_4-s_3858320594.png "alt=" Wkiol1mfudkyoalcaaecsqdgl7e509.png-wh_50 "/>
4.Iterator Iterator (): Represents an iteration (traversal) of an element in a collection
Iterator: interface
Object Next () returns the next element of the iteration. (get Element)
Boolean Hasnext () returns True if there are still elements that can iterate.
650) this.width=650; "title=" iterator. png "src=" https://s4.51cto.com/wyfs02/M01/9D/C6/ Wkiom1mfuhfgo4ncaadg2snbsa8333.png-wh_500x0-wm_3-wmp_4-s_1165545918.png "alt=" Wkiom1mfuhfgo4ncaadg2snbsa8333.png-wh_50 "/>
The 5.List collection is a sub-interface of the collection collection, and the iterator () method inside of you can also be used in my list!
The relationship between interface and interface is an inheritance relationship!
list Collection Proprietary Iteration traversal method
listiterator listiterator ();
650) this.width=650; "title=" list 1.png "src=" https://s1.51cto.com/wyfs02/M01/9D/C6/ Wkiol1mfui-cd1k6aace5lg6wdo111.png-wh_500x0-wm_3-wmp_4-s_3391650775.png "alt=" Wkiol1mfui-cd1k6aace5lg6wdo111.png-wh_50 "/>
Listiterator Interface:
Boolean Hasnext (): Indicates a forward traversal: whether there is a next element that can be iterated
Object next (): Gets the next element
Boolean hasprevious (): Indicates a reverse traversal: whether there is an element that can be iterated over
Object Previous () returns the previous element in the list
There is a sequential problem: to use the reverse traversal, you must first traverse, if the first backward traversal, no meaning, generally do not use!
650) this.width=650; "title=" list 2.png "src=" https://s1.51cto.com/wyfs02/M02/9D/C6/ Wkiom1mfukjsupq5aadhlt4jd2s304.png-wh_500x0-wm_3-wmp_4-s_600257237.png "alt=" Wkiom1mfukjsupq5aadhlt4jd2s304.png-wh_50 "/>
JAVA---Collection section (1)