Learning Java collections starting from collection, the collection interface extends the iterable interface. All classes that implement the iterable interface can use the enhanced for loop, that is, foreach (foreach is one of the new features of Java 5 ). Before learning Java collections, you need to figure out the relationship between interfaces and implementations and draw only a part of them. The update process will be supplemented later. (Here, I declare that I am a detail-oriented person, and the text record is only a process of self-Learning Improvement. If there is a mistake, please kindly advise, if you need to pay attention to the details of the discussion, it is no longer necessary. Thank you in advance !)
The source code of the collection is as follows:
Public Interface collection <E> extends iterable <E> {/*** returns the number of elements in the set. if the number of sets is greater than integer. max_value, return integer. max_value. */INT size ();/*** returns true if the set does not contain any element. */Boolean isempty ();/*** returns true if the set contains the specified element. only at least one element in the Set meets the condition (O = NULL? E = NULL: O. true is returned only when equals (e) is used. * judge whether the parameter o is null. If it is null, execute O. equals (e) will report nullpointerexception (you can learn from this to determine whether the object is the same, you can use this ternary operator) * @ throws classcastexception if the specified Element type is incompatible with this collection (optional) * @ throws nullpointerexception if the specified element is null, and this collection does not allow null elements (optional) */Boolean contains (Object O);/*** returns an iterator composed of collection elements (the elements are unordered ). */iterator <E> iterator ();/*** returns an array containing all collection elements. the sequence of the array is the same as that of the iterator. */object [] toarray ();/*** returns an array containing all collection elements. specifies the type of the return value. if the length of the parameter array is greater than the length of the collection, the element in the extra space is null. */<t> T [] toarray (T [] A);/*** returns true if the value is added successfully, and false if the value fails. * @ throws unsupportedoperationexception if this collection is not supportedAddOperation * @ throws classcastexception if the specified Element's class does not allow it to be added to this collection * @ throws nullpointerexception if the specified element is null, in addition, this collection does not allow the null element * @ throws illegalargumentexception. If an attribute of an element is not allowed to be added to this collection * @ throws illegalstateexception if due to insertion restrictions, the element cannot be added */Boolean add (E) at this time;/*** remove a single instance of the specified element from the collection. if at least one element in the Set meets (O = NULL? E = NULL: O. when equals (e) is removed, true is returned. * @ throws classcastexception if the specified Element type is incompatible with this collection (optional) * @ throws nullpointerexception if the specified element is null, and this collection does not allow null elements (optional) * @ throws unsupportedoperationexception if this collection is not supportedRemoveOperation */Boolean remove (Object O);/*** returns true if the set contains all elements in the collection of the specified parameter. * @ throws classcastexception: if the specified collection contains one or more types of elements, this collection is not compatible (optional) * @ throws nullpointerexception if the specified collection contains one or more NULL elements, in addition, this collection does not allow null elements (optional), or the specified collection is null */Boolean containsall (collection <?> C);/*** add all the elements in the collection with the specified parameter to this collection, and return true. * @ throws unsupportedoperationexception if this collection is not supportedAddallMethod * @ throws classcastexception: if the class of an element in the specified collection is not allowed to be added to the Collection * @ throws nullpointerexception if the specified collection contains a null element, and the collection does not support null elements, or the specified collection isNull* @ Throws illegalargumentexception if an attribute of the element of the specified collection is not allowed to be added to this collection * @ throws illegalstateexception if due to insertion restrictions, not all elements can be added */Boolean addall (collection <? Extends E> C);/*** removes all elements in the collection and specified parameter sets, and returns true. * @ throws unsupportedoperationexception if this collection is not supportedRemoveallMethod * @ throws classcastexception if the types of one or more elements in the collection are not compatible with the specified collection (optional) * @ throws nullpointerexception if the collection contains one or more NULL elements, the specified collection does not support null elements (optional), or the specified collection is null */Boolean removeall (collection <?> C);/*** keep all the elements in the collection and the specified parameter set, and return true. * @ throws unsupportedoperationexception if this collection is not supportedRetainallOperation * @ throws classcastexception if the types of one or more elements in this collection are not compatible with the specified collection (optional) * @ throws nullpointerexception if this collection contains one or more NULL elements, the specified collection does not allow null elements (optional), or the specified collection isNull*/Boolean retainall (collection <?> C);/*** remove all elements in the collection unless an exception is thrown. * @ throws unsupportedoperationexception if this collection is not supportedClearOperation */void clear (); // comparison and hashing/*** checks whether the collection is equal to the specified object. */Boolean equals (Object O);/*** return the hash value of this collection. */INT hashcode ();}