Java---Container Basics Summary

Source: Internet
Author: User

Java provides a number of ways to hold objects:

(1) the array links the numbers to the objects. It saves type-specific objects and does not require a type conversion for the result when querying the object. It can be multidimensional and can hold basic types of data. However, once an array is generated, its capacity cannot be changed .

(2) Collection saves a single element, while map saves the associated key-value pair. With Java generics , you can specify the types of objects that are stored in the container, so you do not place objects of the wrong type into the container, and you do not have to type conversions when you get the elements from the container. Various collection and various maps can automatically resize when you add more elements to it. The container cannot hold the base type, but the automatic wrapper mechanism carefully performs a bidirectional conversion between the basic type and the wrapper type held in the container.

(3) like an array, thelist also establishes a numeric index associated with an object, so arrays and lists are well-ordered containers. List can automatically expand capacity.

(4) if you want to do a lot of random access, use ArrayList( with the characteristics of the array ), if you want to frequently insert or delete elements from the middle of the table, you should use LinkedList (features with linked list)

(5) the behavior of various queue (queue) and stack, supported by LinkedList .

(6) Map is a design that associates an object, not a number, with an object. HashMap designed for quick access , while TreeMap keeps the "key" always in the sort state , so there is no HashMap fast. Linkedhashmap preserves the order in which elements are inserted, but also provides quick access through hashing .

(7) Set does not accept duplicate elements. HashSet provides the fastest query speed, while TreeSet keeps elements in a sorted state.
Linkedhashset Saves the element in an insertion order.

Diagram of the Java container (without abstract and legacy artifacts):

As you can see, there are actually only four containers: Map,List ,Set , and Queue, each of which has two to three implementation versions. Commonly used containers are represented by a thick black wireframe.

A dot-wireframe represents an interface, and a solid wireframe represents a normal (specific) class. A dot line with a hollow arrow indicates that a particular class implements an interface, and a solid arrow indicates that a class can generate an object that the arrow points to the class. For example, an arbitrary
Collection can generate Iterator, and List can generate listlterator (and can generate normal Iterator, Because list inherits from Collection)

Java containers are used every day for tools that make programs more concise, powerful, and efficient.

1.Java Container Overview

2.Java Container---basic concepts

3.Java Container---Collection interface

4.Java Container---Arrays & Collections Tool Class

5.Java Container---character container stringbuffer & StringBuilder

6.Java Container---list base

7.java Container---comparable & Comparator

8.Java Container---Set Basics: HashSet & TreeSet & Linkedhashset

9.Java Container---Iterator

10.Java Container---map base

Java---Container Basics 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.