Java Container Framework Summary (i)

Source: Internet
Author: User
Tags iterable

This article according to "Java programming thought" the 11th chapter holds the object collation, summarizes the Java container Frame Common collection class and the interface characteristic and the use scene.

(a) Summary

1) Arrays relate numbers to objects; You can save basic types of data; Once generated, capacity cannot be changed;

2) Collection save a single element, map saves the associated key-value pairs, cannot hold basic types, and when adding more elements, automatically adjusts the dimensions;

3) The list interface inherits from the connection interface, the same as the array, also establishes the digital index and the object association, the array and the list are the orderly container, the ArrayList and the LinkedList all implements the list interface, carries on the massive random access, Use ArrayList; If you frequently insert or delete elements from the middle of a table, you should use LinkedList;

4) The queue interface declares the method of inserting and removing elements in the queue, and the rules of the queues depend on the implementation; FIFO describes the most typical queue rules, the next element should be the longest waiting element, LinkedList implements the queue interface The priority queue declares that the next popup element is the most needed element, and Priorityqueue implements the queue interface;

5) Map is a design that associates an object, not a number, with an object. HashMap through the hash code to achieve the map interface, holding the key value pair is unordered, used for quick access; TreeMap through the red black tree, keep "key" is always in the sort state; Linkedhashmap maintains the insertion order of elements and provides fast access through hashing code;

6) Set does not accept duplicate elements. HashSet provides the fastest query speed by hashing code, TreeSet keeping elements in sort state, linkedhashset saving elements in order of insertion;

7) Iterable interface provides a way to return the iterator interface, connection interface inherits Iterable interface, iterator interface provides Hasnext, next method and optional Remove method;

8) The Listiterator interface inherits from the iterator interface, adding a reverse traversal method and an optional set method; The list interface provides a way to return the Listiterator interface;

9) The comparable interface provides an int compareTo (t o) method, and the comparator interface provides an int compare (T o1,t O2) method.

The Arrays tool class contains various methods for manipulating arrays, such as sorting and searching.

One) the Connections tool class consists entirely of static methods that operate on the Collection or return Collection.

(ii) Precautions

1) Aslist Method of arrays:

aslist (T ... a)
Returns a list of fixed sizes supported by the specified array. (Changes to the returned list are "written straight" to the array.) This approach, together with Collection.toarray , serves as a bridge between an array-based API and an Collection-based API. The returned list is serializable and implemented RandomAccess .

This method also provides a convenient way to create a fixed-length list that is initialized to contain multiple elements:

     List stooges = arrays.aslist ("Larry", "Moe", "Curly");

Java Container Framework Summary (i)

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.