Java Collection Class learning little memory

Source: Internet
Author: User
Tags comparable int size

"List Interface": A mutable array that allows all types of elements to be saved, including NULL, elements can be duplicated, saved in order of addition
"Common Implementation Class": Recommended with ArrayList
ArrayList: Faster index access (but slower insertion and deletion of nodes)
LinkedList: Linked list structure, insert delete node very quickly (but the random Access node object is inefficient)
"Common methods":
Boolean Add (E E)
Boolean remove (Object o)
int size ()
E get (int index)
E set (int index,e)

"Set interface": not sorted in a particular way, elements cannot be duplicated
"Common Implementation Classes": Recommended use of TreeSet
HashSet: Supported by a hash table, which is actually a HashMap instance, does not guarantee that the element order is constant, allowing null
TreeSet: Automatically increment sort by natural order when traversing, allow null
"Common methods":
Boolean Add (E E)
Boolean remove (Object o)
int size ()
"TreeSet Common Methods":
E First (): Minimum element
E last (): Maximum element
Comparator Comparator (): Returns the sort used by the comparer (natural order, then returns NULL)
SortedSet HeadSet (E to): to (not included) a subset of the front
SortedSet subset (E from,e to): from (included) to a subset of to (not included)
SortedSet Tailset (E from): Subset after from (inclusive)

Because the elements in the TreeSet collection automatically call the element's CompareTo () method when they are inserted, the TreeSet in the collection

If the element is a basic type, you do not need to implement the comparable interface "because many classes in Java (including all basic types) have been implemented

Comparable interface ", if the object is a custom type, the type must implement the CompareTo () party in the comparable interface

method is inserted into the TreeSet collection through the Add () method to ensure that automatic sorting does not occur without errors.

"Map Interface": Provides a unique mapping of key to value, without the same key,
Common Implementation classes: HashMap is recommended because it is more efficient to add and remove mappings
TREEMAP: null key not allowed
HASHMAP: The implementation of map interface based on hash table, through hashing technology, using the hash code generated by key as the offset to determine the storage object in the mapping

The location of the shot, allowing null values and NULL keys, but must guarantee the uniqueness of the key
"Common methods":
V get (Object key): Returns the value mapped by the specified key, or null if the mapping does not contain a mapping relationship for the key
V put (K key,v value): Associates the specified value with the specified key in this map. If the map previously contained a mapping for this key, the

Will replace the old value with the new value, return the old value, or return NULL "return null may also indicate that the key mapping was previously pointing to null"
void Putall (map m): Stores the mapping relationship of the specified m in the caller map
V Remove (Object key): If there is a mapping relationship for the specified key, it is removed from this mapping and returns the value associated with the key, no

Returns NULL "returns NULL or may indicate a previous key mapping to NULL"
int size ():
Boolean ContainsKey (Object key): Returns TRUE if this map contains a mapping relationship for the specified key.
Boolean Containsvalue (Object value): Returns True if this mapping maps one or more keys to a specified value
Set KeySet (): Returns the set view of the keys contained in this map (guaranteed key Uniqueness)
Collection<v> VALUES (): Returns the Collection view of the values contained in this map

Java Collection Class learning little memory

Related Article

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.