"Java" collection framework

Source: Internet
Author: User

★ Storage Objects: Arrays, collections
More objects are used in the collection, and the data is stored with objects
★ Different arrays and collections?

    • The length of the array is fixed and the set length is variable

    • Only objects of the same type can be stored in an array, and only the objects stored in the collection are rows

★ Set Frame: is constantly upward extraction of common
The collection framework contains a large collection of interfaces and their implementation classes and algorithms for manipulating them (such as sorting, iterating, finding, and so on), collection mainly provides list (list), queue, set (set), The data structures such as stack (stack) and map (map tables, which hold key-value pairs), where list, Queue, Set, and stack inherit from the collection interface.
Why are there so many containers?
Because each container has different ways of storing data, this storage is called: Data structure. Each container is separate because of the different data structures, because they are structurally distinct.

Collection, located at the top of the entire set frame, is the basis for the entire set framework, which stores a set of objects representing different types of collections, and it serves only to provide a basic interface for maintaining a set of objects.

The three most commonly used interfaces in collection are list, Set, and Map.

    • List (ArrayList, Linkeslist, Vector)

List, also known as an ordered collection, stores objects in the order in which they are entered, so it can accurately judge the position of each element in the list, facilitates the control of the position of the element by inserting and deleting operations, and it can also save duplicate objects. .

    • Set (HashSet, TreeSet)

Set represents a collection, the main feature is that the elements in the collection cannot be duplicated , so each element that is stored in a set must define the Equals () method to ensure the uniqueness of the object.

The TreeSet implements the SortedSet interface, so the elements in the TreeSet container are ordered.

    • Map (HashMap, TreeMap, Linkedhashmap, Weakhashmap, Identityhashmap)

Map provides a data structure that maps from a key to a value to hold a key-value pair, where the value is repeatable, but the key must be unique (and the concept of the map is the same, can be one-to-many but not many-to-a).

Although the classes listed above can implement the map interface, their execution efficiency is different

The HashMap is based on the hash list, and the hashcode of the object can be used for quick query.

Linkhashmap use lists to maintain the internal order;

TreeMap is based on the data structure of the red-black tree, and the inner elements are ordered sequentially.

Map is an interface, so you cannot instantiate a map object directly, but you can instantiate the object of the class that implements the map interface, such as: Map Hera = new HashMap ();


Collection Frame class diagram


650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/5B/92/wKiom1UL4p-AcisaAAIv-teA5vA381.jpg "title=" 20120921030244923.png "alt=" Wkiom1ul4p-acisaaaiv-tea5va381.jpg "/>


Image Link: http://www.2cto.com/uploadfile/2012/0921/20120921030244923.png

"Java" collection framework

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.