The characteristics of a collection
- interface: is an abstract data type that represents a collection. The interface allows the collection to manipulate the details of its representatives independently. In object-oriented languages, interfaces usually form a hierarchy.
- implementation (Class): is the specific implementation of the collection interface. Essentially, they are reusable data structures.
- algorithm: is a useful calculation for the execution of methods in an object that implements a collection interface, for example: Search and sort. These algorithms are called polymorphic, because the same approach can have different implementations on similar interfaces.
Two, set frame diagram
Iii. generic methods
You can write a generic method that can receive different types of arguments when it is called. Depending on the type of argument passed to the generic method, the compiler handles each method call appropriately.
The following is the rule that defines a generic method:
- All generic method declarations have a type parameter declaration part (delimited by angle brackets) that is part of the type parameter declaration before the method return type (<E> in the following example).
- Each type parameter declaration section contains one or more type parameters, separated by commas between the parameters. A generic parameter, also known as a type variable, is the identifier used to specify a generic type name.
- A type parameter can be used to declare a placeholder for the actual parameter type that returns a value type and can be obtained as a generic method.
- The declaration of a generic method body is the same as other methods. Note that the type parameter can only represent a reference type, not the original type (like Int,double,char, and so on).
Java Collection Framework