Collections in Java

Source: Internet
Author: User
Tags set set

definition of a collection

The capacity of the collection can be expanded automatically and more flexible in programming;

The array can hold either the base data type or the reference data type;

And the collection class can only hold the reference data type;

Classification of collections

1, Collection interface-linear set; Each element has only one precursor, and there is only one successor;

A) List interface-can hold ordered duplicate elements, List set is subscript, you can use subscript to access the element;

1, ArrayList-Internal is to use an array to store elements, the initialization of the definition of 10 elements of the object array, when the element exceeds the maximum, will generate a new array, the length is 1.5 times times the original array, with a new array to replace the old array;

Features: Fast query speed, slow insertion and deletion, elements in the logical structure and physical structure are continuous;

2, LinkedList-the internal use of linked lists, provides a number of special methods can be used as a stack or queue to use;

Features: Slow query speed, fast insertion and deletion, logical continuous, physical discontinuity;

b) Set interface-can store unordered non-repeating elements, set set without subscript, elements can not be accessed by subscript;

1, HashSet-the position that the element is deposited into the collection is determined by the hash code of the element; Hashcode (); The internal is also an array implementation;

2, TreeSet-The elements are sorted, and the elements placed into the TreeSet collection must be sortable;

Iterator-Iterator interface. Iterator (); method to generate an iterator object;

Ordered/unordered-ordering refers to the order in which elements are deposited into the set and the order in which the elements are stored in the collection;

-disorder refers to the order in which elements are deposited into the collection and the order in which the elements are stored in the collection;

Repeat-if A and B two elements are satisfied a.equals (b) = = True, then A and B are considered duplicates; for example, "Hello" is duplicated with the new String ("Hello").

2. Map interface-nonlinear set; the elements are stored in the form of key-value (key-value pairs);

1, HashMap-the position of the element in the collection is related to the hash code of the key; Hashcode ();

2. TreeMap-The elements are sorted in the order of the keys;

generic type

Parametric point<t> of generics-type

The base data type cannot be an argument to a generic, and must be a reference data type;

Summary

PS: The following content is transferred from the network

Set Set:
HashSet: The implementation of a set using HashMap. Although the set is defined as unordered, there must be some way to find an object fairly efficiently. Storage and retrieval operations that use an HashMap object implementation set are implemented in a fixed time period.
TreeSet: The implementation of a set that sorts objects in ascending order. This means that getting the first iterator from a TreeSet object will provide the object in ascending order. The TreeSet class uses a treemap.
List:
Vector: Implements an array-like table that automatically increases capacity to accommodate the elements you need. Using subscripts to store and retrieve objects is just like in a standard array. You can also use an iterator to retrieve objects from a vector. Vector is the only synchronization container class?? Performance is also good when two or more threads are accessed at the same time.
Stsck: This class derives from the vector and adds a method implementation stack?? A last-in-first-out storage structure.
LinkedList: Implements a linked list. A linked list defined by this class can also be used as a stack or as a queue.
ArrayList: Implements an array that is variable in size and can be accessed like a linked list. It provides functionality similar to the vector class but is out of sync.
Mapping Map:
HashTable: Implements an image, all keys must be non-empty. In order to work efficiently, the class defining the key must implement the Hashcode () method and the equal () method. This class is an inheritance of the previous Java implementation and is usually better used in other classes that implement the image.
HashMap: Implements an image that allows an empty object to be stored, and allows the key to be empty (since the key must be unique, of course there can be only one).
Weakhashmap: Implements such an image: Usually if a key is no longer referenced to an object, the key/object pair is discarded. This is in contrast to the HashMap, where the key in the image maintains the life cycle of the key/object pair, although the program using the image no longer has a reference to the key, and therefore cannot retrieve the object.
TreeMap: To implement such an image, the object is in ascending order of keys. Both the
Set and list are extended by the public interface collection, so they can all be referenced using a variable of type collection. This means that any collection of lists or sets can be referenced in this way, except for the mapping class (but not completely excluded, because a list can be obtained from the map.) So, the standard way to pass a list or set to a method is to use the collection type parameter.

Collections in Java

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.