Interface Java.lang.Iterable is the parent interface of the Java.util.Collection interface, but occurs later regardless of the interface Java.util.Collection interface is a hierarchical interface with the interface java.util.list< ; The implementation class under the E> interface allows the storage of duplicate element interfaces java.util.set<e> the implementation class under the interface does not allow the storage of repeating element classes Java.util.arraylist<e> class Java.util.LinkedList <E> class java.util.hashset<e> Class Java.util.linkedhashset<e> interface Java.util.Collection method:
| Method declaration |
Function description |
| Boolean |
Add (e) ensures that this collection contains the specified element (optional action). |
| void |
Clear () Removes all elements from this collection (optional action). |
| Boolean |
Contains (Object o) returns True if this collection contains the specified element. |
| Int |
Size () returns the number of elements in this collection. |
| Boolean |
Remove (Object o) Removes a single instance of the specified element from this collection, if one exists (optional action). |
| Object[] |
ToArray () Returns an array that contains all the elements in this collection. |
Collections without fixed-length arrays have fixed-length collections that cannot store basic types (four classes of eight types) can only store their reference types "< data types to store elements >" Data types must be reference data types, not basic data types; The following is a representation of the reference data type for the 8 basic data types:
| Byte |
Short |
Int |
Long |
Float |
Double |
Char |
Boolean |
| Byte |
Short |
Integer |
Long |
Float |
Double |
Character |
Boolean |
Let's take a few examples to clarify how the collection is created: storing elements of type String arraylist<string> list = new arraylist<string> (); L store data of type int arraylist<integer> list = new arraylist<integer> (); Store Phone type data arraylist<phone> list = new arraylist<phone> ();
Collections in Java