A summary of the relevant basis of the collection comparison learning

Source: Internet
Author: User
Tags comparable

String cannot change the length of a character is actually pointing to another string object
StringBuffer Synchronous use a box to load the string in
StringBuilder the strings in a box in different steps. 2 The only difference is synchronization.


Framework
Collection: A reference to an object that is stored in the collection (address)
List: Elements are ordered and elements can be duplicated. Because the collection system has an index. All the methods that can operate the angle mark are the methods peculiar to the system.

ArrayList:
The underlying data structure uses the array structure. Features: Fast query speed. But additions and deletions are slightly slower. Thread is out of sync.
LinkedList:
A linked list data structure used at the bottom. Features: Deletion speed quickly, query slightly slow. Thread is out of sync.
Vector:
The bottom layer is the array data structure. Thread synchronization. Replaced by the ArrayList. Because the efficiency is low.
Features enumeration interface
Enumeration is the unique way to take out vectors.
Set: Elements are unordered (the order in which they are deposited and taken out is not necessarily consistent), and elements cannot be duplicated.
TreeSet: two fork tree structure. Thread is out of sync. The functions and collection of the set set are consistent.
There are default sorting elements that cannot be sorted into the 2nd one will exception
Guaranteed element Uniqueness CompareTo method return 0.
2 Kinds of sorting methods. One is that the element has its own comparative one is the set initialization to increase the comparator
HashSet: Hash table structure. Thread is out of sync. Guaranteed element Uniqueness (hashcode and equals)
The hash value is the same as the object before it is seen.

Generics: ClassCastException The run-time problem, moving to the compile time.
The Special place:
Static methods do not have access to generics defined on the class.
If the application data type for a static method operation is undefined, you can define the generic on the method

? A wildcard character. Can also be understood as placeholders.
The qualification of generic type;
? Extends e: Can receive subtypes of type E or E. Ceiling.
? Super E: Can receive the Type E or the parent of E. Lower

Comparable: Interfaces make objects comparable.
Comparator: Used when the object itself is not comparable, or if the comparison is not required. Create a new class to implement the interface. Overriding the Compare method

MAP:
|--hashtable: Hash table structure, cannot be stored as null key null value. The collection is thread-synchronized. Low efficiency.
|--hashmap: Hash table structure, which allows null values and NULL keys to be used, is not synchronized. High efficiency.
|--treemap: The bottom layer is a two-fork tree data structure. Thread is out of sync. Can be used to sort the keys in the map collection.
Two ways to remove a map collection:
1. Get key. Obtain the corresponding value from the Get method by keyset the collection of keys by iterator each key out.
2. Get the key and value correspondence. Get a one-to-one relationship by EntrySet set set by Itrator to get map.entry types of objects.
When you get the key or value
Iterator: The way the collection is taken out of the element.
Iterator
Listiterator:list's unique iterator list is ordered and indexed, so a unique method is added.
Map.entry<k,v>: Interface, a subclass object is basically a pair of key and value mappings. Obtain the corresponding data by means of the method.

The main differences between iterator and Listiterator are:
One, Listiterator has the Add () method, you can add objects to the list, and iterator cannot.
Both Listiterator and iterator have Hasnext () and Next () methods, which can be traversed sequentially. However, Listiterator has the hasprevious () and Previous () methods, which enable reverse (sequential forward) traversal. Iterator is not allowed.
Third, Listiterator can locate the current index position, Nextindex () and Previousindex () can be implemented. Iterator does not have this feature.
Four, can implement delete object, but Listiterator can implement object modification, the set () method can be implemented. Iterator can only traverse and cannot be modified. Because of these functions of listiterator, we can implement the operation of the list data structure such as LinkedList.

A summary of the relevant basis of the collection comparison learning

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.