Java -- collection -- List, Set, Map

Source: Internet
Author: User

Set: Data Structure
 
Abstract data
Data Operation Method
Abstract data type
Data operation method + Data
 

Collection
 
Iterator: only the elements can be traversed in the forward order, and the elements can be deleted while traversing.
 
ListIterator
Forward Traversal
Post-order traversal: you must first move the iterator to the end of the set to traverse from behind
Insert element: add an element to the left of the iterator's current position
Delete element:
Traverse the elements on the left of the iterator in the forward order.
Post-order traversal deletes the right element of the iterator
Modify element:
An element must be skipped before modification.
Can be modified multiple times in a row
Obtain the current index (subscript)
 
 

List:
Focus on the index and sequence of Elements
Element duplication allowed
 
ArrayList dynamic array/Generic Array
Advantages:
Fast traversal and Random Access
Disadvantages:
Insertion and deletion are slow, occupying continuous memory space
 
Linked List
One-way, non-cyclic linked list
One-way cyclic linked list
Bidirectional non-circular linked list
Bidirectional cyclic linked list
 
Headless linked list
Advantages:
Insert, fast Deletion
Disadvantages:
Random Access is not provided. The subscript used indicates the number of nodes passing through the node from the first node.

Stack: First releases FirstInLastOut
Queue: first-in-first-out FirstInFirstOut
 
 
Set: Hash --> Hash
Ignore element index
Repeated elements are not allowed.
Calculate element Subscript: hashCode % bucket (array length)
 
HashSet
Unordered, unclassified set
The hashCode and equals methods must be rewritten for custom objects.
Provides a basis for HashSet to determine whether objects are the same
 
LinkedHashSet
Sort the Hash version strictly by the insertion order
 
TreeSet
Hash sort version, sorted by element size
Sorted from small to small by default
 
Equals: compare whether the content of two objects is the same
 
CompareTo: Compare the size of two objects
It must be rewritten. This method must be rewritten when a custom object is created.

HashCode and equals
When all attributes of two objects are the same
The two objects are the same object.
 
 

Map
Key-value ing relationship
Key uniqueness

HashMap
Unordered
Without an iterator, you can only traverse the view.
 
Entry view key-value
Key View
Value View
 
LinkedHashMap
Sort by element order

TreeMap
Sort by key size

Comparator: Comparator
Tells TreeMap how to sort elements in a set
Custom sorting rules
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.