1, set: Objects in the collection are not sorted in a particular way, and there are no duplicate objects, and some implementation classes can sort the collections in a particular way
List: Objects in the collection are sorted by index location, can have duplicate objects, allow the object to be retrieved by the index location in the collection, and the list and array are somewhat similar.
Map: Each element in the collection contains a pair of key objects and value objects, the collection rollup has no duplicate key objects, and the value objects can be duplicated. Some of its implementation classes can sort the key objects in the collection.
The 2,set and List interfaces inherit the collection interface.
The ' Collection ' interface iterator () and ToArray () are used to get all the elements in the collection.
The Iterator interface hides the data structure of the underlying collection, providing the client with a unified interface to traverse the various types of collections.
Iterator declares the following methods:
Hashnext () determines whether the elements in the collection are traversed to completion
Next () returns the next element
Remove () Removes the previous element returned by the next () method from the collection.
3, Set set:
The Set interface has two implementation classes: HashSet and TreeSet
HashSet access speed is faster, HashSet and sub-class Linkedhashset (that is, the implementation of the hashing algorithm, but also the data structure of the linked list, linked list data structures can improve the performance of inserting and deleting elements.
TreeSet implements the SortedSet interface and has the sort function.
General usage of set: the comparison of whether objects in set are equal is compared with equals
HashSet: The comparison is between the hash code and the Equals
TreeSet: When adding data to a collection, it is inserted into an ordered sequence of objects. TreeSet supports two sorts of natural sorting and customer ordering, the default being natural sorting.
A> Natural Sort: A classification (integer,double,string), etc., implements the comparable interface has a CompareTo (Object O) method that returns an integer type.
A.compareto (b) returns 0 A = = B, returns less than 0 a < B, returns > 0 a > B.
The b> customer sort Java.util.comparator<type> interface provides a specific sorting method. Comparator has a compare (Type X,type y)
4, ArrayList: variable-length array that allows fast random access to elements, but is slower to insert and delete data into the ArrayList.
linklist: A linked list data structure is used in the implementation.
Linklist alone has AddFirst (), AddLast (), GetFirst (), GetLast (), Removefirst (), Removelast (). These methods can be used as stacks, queues, and bidirectional queues.
5, the Collections class is a helper class in the Java Collection Class library.
Sort list: Natural sorting of objects in list
Sort (List List,comarator comparator): Sorts the objects in the list, comparator the parameters to specify the sort method.
6, Listiterator:list's Listiterator () method returns a Listiterator object.
Listiterator:add () Inserts an element into the queue.
Hashnext () Determines if there is a next element.
Hasprevious () determines the previous element in the list.
Next () returns the next element in the list.
Previous () returns the previous element in the list.
7, collections The method applies to the collection of list types.
Copy (list dest,list src) copy elements from a list to another list
Fill (List List,object o) fills the list with elements.
Sort (list List) in natural order.
BinarySearch (list List,object key) looks for the same element in the list as the given object key.
BinarySearch (List list,object key,comparator C) When calling this method, you must ensure that the elements in the list are sorted according to the comparison rules of the parameters of the Comparator type.
The shuffle list lists the elements in a random order.
Introduction to Java Collections