Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are Vector,ArrayList,LinkedList respectively?

2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "what is Vector,ArrayList,LinkedList". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what is Vector,ArrayList,LinkedList respectively".

Speaking of Vector,ArrayList,LinkedList, Java developers must be very familiar with these three categories, which are basically sent every month or even every week, so netizens call this kind of blog or reply post grave digging.

Confucius said well, "if you review the past and learn the new, you can be a teacher" (I'm sure it's not what Lu Xun said).

Even if we remember the classes and functions we know very well, sometimes it is necessary to pull them out and review them.

Let me not talk about the difference in definition between these three classes. Let's first look at the performance index, the same add and delete 10w and integers, in the add and delete time-consuming situation.

Insert speed: what is less obvious is that in terms of insertion, LinkedList is about twice as fast as Verctor and ArrayList. Of course, there is not much difference in the effect on a small amount of data. All comparisons leaving the scene are rogue. To be clear, Vector adds a lock to the method when inserting elements. You must know that locking is a safe but expensive thing for CPU. So generally speaking, whether the method is implemented by yourself or native, you should carefully judge whether you need to use a lock.

Public synchronized boolean add (E e) {modCount++; ensureCapacityHelper (elementCount+ 1); elementData [elementCount++] = e; return true;}

Delete speed: this gap is very obvious, why is LinkedList so good? Then what's the use of ArrayList? Hey, hey, don't worry, look at the speed of the visit first.

Visiting speed: wow, there is such a difference? Just now I praised you for being excellent. I'll use you as a ghost. You're a bad old collection. In fact, this is because its implementation is a two-way linked list, access to an element can only be kept looking for next, found before returning, can not be found through the subscript.

Public boolean remove (Object o) {if (o = = null) {for (Node x = first; x! = null; x = x.next) {if (x.item = = null) {unlink (x); return true;}} else {for (Node x = first; x! = null) X = x.next) {if (o.equals (x.item)) {unlink (x); return true;} return false;}

So here you know how to choose to use the collection you need, right?

Thank you for your reading, the above is the content of "what is Vector,ArrayList,LinkedList respectively", after the study of this article, I believe you have a deeper understanding of what Vector,ArrayList,LinkedList is, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report