| |

VerySource

 Forgot password?
 Register
Search
View: 1270|Reply: 10

ArrayList, LinkdList, HashMap, Vector in the java.util package collection class

[Copy link]

3

Threads

11

Posts

10.00

Credits

Newbie

Rank: 1

Credits
10.00

 China

Post time: 2020-2-16 08:00:01
| Show all posts |Read mode
Talk about some connections and differences between the ArrayList, LinkdList, HashMap, and Vector classes in the collection class?
Reply

Use magic Report

0

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 Australia

Post time: 2020-4-18 07:45:01
| Show all posts
ArrayList, LinkedList, and Vector are all List implementation classes. The first two do not implement the synchronization mechanism. Vector implements the synchronization mechanism. ArrayList represents an array of variable size. It allows fast random access to elements, but it is added and removed from the middle of the List. The efficiency of element operations is very poor. LinkedList uses a linked list data structure, which optimizes sequential access and improves the efficiency of operations in the middle of the List. The role of Vector is similar to ArrayList, except that it is different from one that implements the synchronization mechanism, and none.

HashMap is an implementation class of Map, which uses a hash algorithm to access Key objects and has good access performance. And allows null to be the Key or Value of Map, HashMap also does not implement the synchronization mechanism.

There is a very detailed introduction in the book,
Reply

Use magic Report

0

Threads

4

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-4-20 19:45:01
| Show all posts
After learning the data structure, everything is clear :)
Reply

Use magic Report

3

Threads

11

Posts

10.00

Credits

Newbie

Rank: 1

Credits
10.00

 China

 Author| Post time: 2020-4-24 19:45:01
| Show all posts
To be specific
Why is it clear after learning the data structure?
Reply

Use magic Report

0

Threads

4

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-4-25 09:30:02
| Show all posts
After learning the data structure, you can also write your own ArrayList, LinkdList, HashMap, Vector

Hehe
Reply

Use magic Report

0

Threads

4

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-4-25 10:15:01
| Show all posts
For example, the difference between a linked list and an array
Must have knowledge of data structure to understand
And trees ...
Reply

Use magic Report

3

Threads

11

Posts

10.00

Credits

Newbie

Rank: 1

Credits
10.00

 China

 Author| Post time: 2020-4-26 09:30:01
| Show all posts
Oh! Understand, now I just learned the basic usage of the methods in those four categories. I want to see some of their connections!
Reply

Use magic Report

3

Threads

11

Posts

10.00

Credits

Newbie

Rank: 1

Credits
10.00

 China

 Author| Post time: 2020-5-31 16:15:02
| Show all posts
Why didn't anyone come? Go ahead, want to see
Reply

Use magic Report

0

Threads

63

Posts

42.00

Credits

Newbie

Rank: 1

Credits
42.00

 China

Post time: 2020-6-1 21:00:01
| Show all posts
Reply

Use magic Report

0

Threads

63

Posts

42.00

Credits

Newbie

Rank: 1

Credits
42.00

 China

Post time: 2020-6-1 21:15:01
| Show all posts
HashMap is not comparable to the other three.

AL, LL, V are all List,

AL and V are based on dynamic arrays, and LL is based on (bidirectional) linked lists, so LL is more suitable for frequent insertion and deletion operations
The methods of AL and LL are not synchronized, while V is synchronized
Since LL is a linked list, there is no such problem as initial size and expansion strategy
The initial size can be specified in the constructors of AL and V, and the default is 10 (so you should specify in advance when you can determine the approximate range of the number of things you want to put, to avoid multiple reallocations)
When AL needs to be expanded * 1.5, and V defaults * 2, and V can be specified to become larger each time, such as 10 expansion each time, rather than double
The constructors of the three, and the addAll method can help convert between each other to improve performance in large batch operations at different stages
V is relatively old and belongs to the veteran of the JDK. As early as JDK 1.0 before java.util.Collection / List appeared, it was there. So in some cases, for example, the Applet is also used under the MS VM, you can only use Vector
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list