Differences and relationships between common interfaces, classes in Java collection classes

Source: Internet
Author: User

I. Vector and ArrayList

1, synchronization: Vector is thread-safe (synchronous), and ArrayList is thread-unsafe synchronization;

2. Data growth: When growth is needed, the vector defaults to one-fold growth, while ArrayList grows by half;

Second, Collection, Set, List, LinkedList

Collection: There is no specified order between the elements objects, allowing for duplicate element objects and multiple null element objects (without the first few elements);

Set: There is no specified order between the elements objects, no duplicate element objects are allowed, and a maximum of one null element object is allowed (nor is there any argument for the first element object);

List: Each element object has a specified order, allowing for duplicate element objects and multiple null element objects, with the argument of the first few element objects, which can be sorted.

LinkedList: Implements the list interface, allows null element objects, in addition LinkedList provides additional Get,remove,insert methods at LinkedList's header or tail. These operations enable LinkedList to be used as stacks (stack), queues (queue), or bidirectional queues (deque). Note LinkedList does not have a synchronization method, and if multiple threads access a list at the same time, you must implement access synchronization yourself. One workaround is to construct a synchronized list when the list is created:
List List = Collections.synchronizedlist (new LinkedList (...));

Iii. Collection and collections

Collection: Is the interface of the java.util, it is the parent interface of various sets, inherited from his interface is mainly set and list;

Collections: Is the Java.util under the class, is for the collection of Help class, provides a series of static methods to achieve the various sets of search, sorting, thread security operations.

Iv. Collection class inheritance structure diagram

Collection
├list
│├linkedlist
│├arraylist
│└vector
│└stack
└set
Map
├hashtable
├hashmap
└weakhashmap

You can see from the structure diagram that the list and set are inherited from the collection interface, whereas the map is not.

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.