First, Javase_ collection (set simple to understand, Collection, List)

Source: Internet
Author: User
Tags array length

Set (i)

first, the simple understanding of the collection

1. Kan kan

Set, that is, to store the data , remember the OOP, we have said that OOP put the data first, and then consider the algorithm to manipulate the data. That is, research data storage, or data structure, let's not talk about data structure of those things. Collections are used to hold data, and there are different ways of storing data, such as arrays, collections. What's the difference between a set and an array?

Difference
Array

1. Arrays can store both the base data type and the reference data type, the base data type stores the value, and the reference data type stores the address value .

2. The array length is fixed and does not grow automatically

Collection

1. The collection can store only reference data types (objects), and the base data types are stored in the collection, but are automatically boxed into objects when stored.

2. The length of the set is variable , and can grow according to the increase of the element

you must know when to use the array when using the collection of it ~

Arrays: Arrays are recommended when elements are fixed.

Collections: When elements are not fixed, it is recommended to use collections.

2. A preliminary understanding (collection Architecture)

The dishes are coming,:

The picture reflects the characteristics of each set, as we use different tools when cooking in the pot, and different bowls and plates have different effects.

Next we'll focus on list.

Collection is the root interface of a single-column collection, in which he has two sub-interfaces. One is list, one is set. Today the main analysis list, namely Arraylist,linkedlist, and vector (understanding).

A list is an ordered collection that can store duplicates. Let's take a look at this code,list List = new ArrayList (); Note: This is not considered generic, the next meeting, not to pipe.

The list interface points to the specific implementation of subclasses, and ArrayList stores an ordered set, which increases as the storage element grows. Similarly, LinkedList is the same, so what is the difference between LinkedList and ArrayList?

If you want to know the difference, then you need to know how the bottom is achieved? Make a table of the above chart.

ArrayList The bottom layer is implemented using arrays .
LinkedList The underlying use of a linked list is implemented

One is an array implementation, and the other is a list implementation.

What are the characteristics of an array: array query modification is fast , because the index to check one step in place;

What are the characteristics of a linked list: The list is deleted and added fast , but the query and modification is slow .

Array

* Query, modify fast

* Add, delete slow

Linked list

* Query, modify slow

* Add, delete fast

Ii. features of the list set of three sub-categories

1.

Characteristics
ArrayList
底层数据结构是数组,查询慢,增删快
线程不安全,效率高
LinkedList The underlying data structure is linked list, query slow, delete quickly.
Threads are unsafe and highly efficient.
Vector The underlying data structure is an array, query fast, and delete slowly.
Thread-safe, low-efficiency.

2.

Vector relative ArrayList query slow (thread-safe)
Vector relative LinkedList and deletions (array structure)

The difference between 3.Vector and ArrayList:
Vector is thread-safe and inefficient
ArrayList is thread insecure, high efficiency
Common denominator: All arrays are implemented
The difference between 4.ArrayList and LinkedList:
ArrayList bottom is the array result, query and modify fast
LinkedList bottom is linked list structure, increase and delete faster, query and modify relatively slow
Common denominator: All threads are unsafe.

5. Since list has three subclasses, how should we choose?

Query Multi- use ArrayList
Adding and removing multi- use LinkedList
If you have more ArrayList (most commonly used)

If there is any mistake, please correct me.

Email: [Email protected]

First, Javase_ collection (set simple to understand, Collection, List)

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.