Java Collection Rough Summary

Source: Internet
Author: User

Collection interface
Public methods:
1. Add () AddAll ()
2. Delete Clear () remove () RemoveAll () Retainall () (take intersection)
3. Judge contains () Containsall () equals () Isempy ()

Two large sub-interfaces:
List interface ordered repetition
ArrayList class Bottom is the array implementation of the deletion rate slow query speed fast synchronization efficiency high
When the same elements are removed, the more complex
Vector class Bottom is also the array to achieve synchronization efficiency at the bottom and delete speed slow query fast

LinkedList class bottom is linked list implementation of the query speed slow and delete faster

Traversal method: 1. Iterator 2.toArray () 3.get () and size () 4.foreach


Set interface unordered Unique
The HashSet class data structure is a hash table that implements unordered and unique ways by depositing the hashcode () in which the object is
Method is implemented with the Equals () method.

TreeSet class unordered unique sort the underlying implementation of the data structure is that the red black tree is naturally sorted by implementing compareable ()
interface, overriding the CompareTo () method to fix the custom comparer class is to implement the Comparetor interface, overriding
Compare () method to get it done.


Common denominator: Iterator (iterator)
Iterating through the collection collection can not use the collection's own additions or deletions while using iterators, only
Use the iterator method to operate, no exception occurs

Map Interface Key-value
Method: Put ()
Remove ()
Clear ()
ContainsKey ()
Containsvalue ()
Get:
KeySet ()
Valuse ()
EntrySet ()
Get ()

HASHMAP Hash table data structure guarantees uniqueness and disorder
Case:hashmap<string,string>
Hashmap<integer,string>
Hashmap<student,string> to override the Student Hashcode () method and the Equals () method
Hashmap<string,student>

TreeMap Red and black tree data structure sorting uniqueness
Case:treemap<string,string>
Treemap<integer,string>
Treemap<student,string> Student to implement the Compareable interface, override the CompareTo method, or customize the comparison class
Treemap<string,student>

The difference between HashMap and Hashtable?
The key and value of 1.HASHMAP can be null
2.HashTable is possible, but we don't usually use it.
3.HashTable is synchronous

Collections Operation Class
1.sort
2.binarySearch find to return to the index, can not find the return (-(insertion point)-1)
3.max
4.reverse (reverse)
5.shuffle (Shuffle) Use default random source to displace a list

Java Collection Rough Summary

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.