Connection Interface Introduction
The connection interface is the root interface of the Java collection, there are no implementation classes, only sub-interfaces and various containers that implement subinterfaces. Used primarily to represent a large abstraction of the Java collection.
The connection interface requires that all containers that implement this interface must provide at least two construction methods: the parameterless constructor method and the constructor for the connection class. The latter needs to create a new collection with the same parameters as the parameter containing elements to replicate the collection. All APIs in Java adhere to this rule.
If the collection does not support a modification, the method that makes this modification must throw a unsupportedoperationexception exception. However, if this modification has no actual effect (such as adding an empty collection to a collection), the collection may not throw this exception.
For some collections, they have restrictions on the elements they can hold, and attempting to add operations may throw unchecked Exception, such as NullPointerException or classcastexception. In the case of a query, the collection may throw an exception, or it may return a false indicating failure, depending on the implementation of the collection itself.
For comparisons of elements in a collection, the collection might use the Equals method, or it might use the Hashcode method, depending on the implementation of the collection. It is not easy to assume that a collection must call the Equals method, and the collection may use the appropriate method provided by any object to compare elements.
In addition, the Clone (), Hashcode (), Equals (), toString () method of the call collection may fail and throw an exception when the collection contains an element that has itself, because this results in a recursive call. The collection can handle this exception on its own, but none of the currently implemented collections are processed.
Methods included in connection
/*** Judgment class method **/intSize ();//returns the element contained in the collection, if greater than Integer.max_value, returns Integer.max_valueBooleanIsEmpty ();//returns True when the collection is emptyBooleanContains (Object o);//returns True when the collection contains O, classcastexception and NullPointerException exceptions may be thrownBooleanContainsall (collection<?>c);/*** Conversion class method **/Iterator<E> iterator ();//returns the corresponding iterator for the collection (this is because connection inherits the Iterable interface)Object[] ToArray ();//convert a collection to an array<T> t[] ToArray (t[] a);//convert a collection to an array and keep the type of input/*** Operation class method **/BooleanAdd (e e);BooleanAddAll (collection<?extendsE>c);BooleanRemove (Object o);BooleanRemoveAll (collection<?>c);BooleanRemoveif (predicate<?Supere> filter);//This method has a default implementationBooleanRetainall (collection<?> c);//only elements in parameters are preservedvoidClear ();
Java.util Package (ii)--connection interface