Java learning --- Collection Interface
Collection Interface
Collection is the most basic Collection interface. A Collection represents a group of objects, namely, Elements of the Collection ). Some collections allow the same elements while others do not. Some can be sorted, while others cannot. Java SDK does not provide classes that directly inherit from collections. Classes provided by Java SDK are "sub interfaces" that inherit from collections, such as List and Set.
All classes that implement the Collection interface must provide two standard constructor: A non-parameter constructor is used to create an empty Collection, A constructor with the Collection parameter is used to create a new Collection, which has the same elements as the imported Collection. The next constructor allows you to copy a Collection.
How to traverse every element in the Collection? Regardless of the actual type of Collection, it supports an iterator () method. This method returns an iterator, and each element in the Collection can be accessed one by one using this iterator. The typical usage is as follows:
Iterator it = collection. iterator (); // get an iteration sub-while (it. hasNext () {Object obj = it. next (); // get the next element}
The two interfaces derived from the Collection interface are List and Set.
Collection ├List │├LinkedList │├ArrayList │└Vector │ └Stack └Set
Obfuscation:
1. java. util. Collection isSet Interface. It provides common interface methods for basic operations on collection objects. The Collection interface has many specific implementations in the Java class library. The Collection interface provides a unified operation mode to maximize various specific sets.
2. java. util. Collections is a packaging class. It contains various Set OperationsStatic polymorphism Method. SuchCannot be instantiated, LikeToolsTo serve the Java Collection framework.
Import java. util. arrayList; import java. util. collections; import java. util. list; public class TestCollections {public static void main (String args []) {// note that List is the List list that implements the Collection interface = new ArrayList (); int array [] = {6, 8, 23, 1, 7}; for (int I = 0; I <array. length; I ++) {list. add (array [I]);} Collections. sort (list); for (int I = 0; I <array. length; I ++) {System. out. println (list. result: 167823