A
The Java language designer has made some specifications (interfaces) and implementations (classes that implement interfaces) for commonly used data structures and algorithms. All abstract data structures and operations (algorithms) are collectively referred to as the collection framework.
The collection in Java can be broadly divided into three major systems: List, Set, MAp. The list represents an ordered set, the set represents an unordered set, and a map represents a collection of mapping relationships.
Two "diagram below
Three "Detailed introduction:
List:
Features: Ordered and repeatable.
Two important implementation classes: ArrayList and LinkedList
1.ArrayList features are ordered and repeatable
2.LinkedList is a doubly linked list structure.
Set:
The set interface inherits from the collection interface, which does not provide an additional method, but the elements in the collection class that implement the set interface are unordered and non-repeatable.
Features: unordered and non-repeatable.
MAP:
Map is also an interface, but does not inherit the collection interface. This interface describes a key-to-value mapping that is never duplicated. The map interface is used to maintain key/value pairs (Key/value pairs).
Feature: It describes a mapping of key-to-value values that are never duplicated.
Two important implementation classes: HashMap and TreeMap
1.HashMap, a key corresponds to a value. The ordering of elements in HashMap is not fixed. More suitable for inserting, deleting, and positioning elements.
The elements in the 2.treemap,treemap maintain some sort of fixed order. More suitable for sequential traversal of elements.
Iterator:
All container classes that implement the collection interface have a iterator method that returns an object that implements the iterator interface. The iterator object is called an iterator,
The iterator interface method iterates through each element of the collection in an iterative manner and removes the appropriate element from the collection, which is commonly used for traversal .
The code demonstrates the following:
Public Static void Main (string[] args) { Collectionnew arraylist<>(); A.add ("A"); A.add ("B"); A.add ("C"); Iterator<String> B = a.iterator (); // Create an iterator while (B.hasnext ()) {// Determine if there is a next element System.out.println (B.next ()); // returns the element } }
Give you a sugar.
<java>collection interface and list interface