Java-Collection Class Summary

Source: Internet
Author: User

Structure diagram:    Collection  ├list  │├linkedlist  │├arraylist  │└vector  │└stack  └set  map  ├hashtable  ├hashmap  
----------------------------------------------------------------------The Collection interface collection is the most basic collection interface, and a collection represents a set of object, the collection element (Elements). Some collection allow the same elements while others do not.             Some can sort and others can't.            Map interface Note that map does not inherit the collection interface, and map provides a key-to-value mapping.      A map cannot contain the same key, and each key can only map one value. The map interface provides a view of 3 collections, and the contents of the map can be treated as a set of key sets, a set of value sets, or a set of key-The value mapping. ------------------------------------------------The list interface differs from the Set interface: list allows the same elements, and set does not allow vectors to be distinguished from ArrayList: vectors are very similar to ArrayList, but vectors are synchronous. The iterator created by the vector, although the same interface as the iterator created by ArrayList, but because the vector is synchronous, when a iterator is created and is being used, another thread changes the state of the vector (for example, adding  or remove some elements), the iterator method will be called when the concurrentmodificationexception is thrown, so the exception must be caught. Stack class: Stack inherits from Vector and implements a last-in-first-out stack.            The stack provides 5 additional ways to make the vector available as a stack.      The basic push and pop methods, and the Peek method to get the stack top element, the empty method tests if the stack is empty, and the search method detects the position of an element on the stack.  Stack has just been created as an empty stack. ------------------------------------------------Summary If involved in stacks, queues and other operations, should consider using the list, for the need to quickly insert, delete elements, should use LinkedList, if you need to quickly randomly access elements, you should use ArrayList.    If the program is in a single-threaded environment, or if access is done only in one thread, it is more efficient to consider non-synchronous classes, and if multiple threads may operate on a class at the same time, the synchronized classes should be used.    Pay special attention to the operation of the hash table, and the object as key should correctly replicate the Equals and Hashcode methods. Try to return the interface rather than the actual type, such as returning a list instead of ArrayList, so that if you need to change ArrayList to LinkedList later, the client code does not have to be changed.   This is for abstract programming. 

Java-Collection Class 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.