Collection schema for the Java Collection
First, we explain the collection. Let's take a look at the diagram of some of collection's framework classes:
Collection is an interface whose main two branches are:List and Set. Both the list and the set are interfaces that inherit from the collection. list is an ordered queue, the list can have duplicate elements , and set is a set of mathematical concepts, set does not have duplicate elements ! Both the list and the set have their own implementation classes. such as ArrayList LinkedList Vector Stack
For convenience, we abstracted the Abstractcollection abstract class, which implements most of the functions in the collection, so that in collection's implementation class, we can omit the repetitive encoding by inheriting abstractcollection.
Both Abstractlist and abstractset inherit from the Abstractcollection, and the specific list implementation class inherits from the Abstractlist, and the set implementation class inherits from the Abstractset.
In addition, there is a iterator () function in collection that returns a iterator interface. Typically, we iterate through the collection through the iterator iterator. Listiterator is unique to the list interface, and in the list interface, a Listiterator object is returned through Listiterator (). Next, we look at the various interfaces and the introduction of the abstract classes, and then the implementation class for a detailed understanding.
Next we look at the collection interface:
PackageJava.util;Importjava.util.function.Predicate;ImportJava.util.stream.Stream;ImportJava.util.stream.StreamSupport;/*** Inherits the Iterable interface, Iterable is an iterator interface with an abstract method that returns an iterator*/ Public InterfaceCollection<e>extendsIterable<e> { intSize ();//returns the number of collection elements BooleanIsEmpty ();//is empty BooleanContains (Object o);//whether the object exists in the collectionIterator<E> iterator ();//inherited from the iterable.object[] ToArray ();//To convert a collection to an object array<T> t[] ToArray (t[] a);//converting a collection to an array of a specific type BooleanAdd (e e);//Add BooleanRemove (Object o);//Delete BooleanContainsall (collection<?> c);//whether this collection is the same as the parameter collection BooleanAddAll (collection<?extendsE> c);//Add a collection BooleanRemoveAll (collection<?> c);//remove elements from all parameter collections in this collection BooleanRetainall (collection<?> c);//retain reserved voidClear ();//Clear BooleanEquals (Object O);//method in Object intHashcode ();//hash Function default BooleanRemoveif (predicate<?SuperE> filter) {//If there is a delete, the interface is implemented by defaultObjects.requirenonnull (filter); Booleanremoved =false; FinalIterator<e> each =iterator (); while(Each.hasnext ()) {if(Filter.test (Each.next ())) {each.remove (); Removed=true; } } returnremoved; } @OverridedefaultSpliterator<e>Spliterator () {returnSpliterators.spliterator ( This, 0); } defaultStream<e>Stream () {returnStreamsupport.stream (Spliterator (),false); } defaultStream<e>Parallelstream () {returnStreamsupport.stream (Spliterator (),true); }}
Collection Interface
Collection schema for the Java collection