In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article is to share with you about the differences between ArrayList and Vector. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Both of these classes implement the List interface (the List interface inherits the Collection interface). They are both ordered sets, that is, the positions of the elements stored in these two sets are sequential, which is equivalent to a dynamic array. We can later extract an element by the location index number, and the data in it is allowed to be repeated, which is the biggest difference between sets such as HashSet. Collections such as HashSet cannot retrieve elements by index number, nor do they allow duplicate elements (the original question has nothing to do with hashset, but in order to clarify the functions of ArrayList and Vector, we use comparison, which is more helpful to illustrate the problem).
Then we talk about the difference between ArrayList and Vector, which mainly includes two aspects:.
(1) synchronization:
Vector is thread-safe, that is to say, its methods are thread-synchronized, while ArrayList is not thread-safe, and its methods are not thread-synchronized. If only one thread will access the collection, it is best to make
Use ArrayList because it doesn't think about thread safety and is more efficient; if more than one thread accesses the collection, it's better to use Vector, because we don't have to think about and write thread-safe code ourselves.
Note: for Vector&ArrayList, Hashtable&HashMap, keep in mind that Vector and Hashtable are old, provided by java as soon as they are born, they are thread safe, ArrayList and HashMap are provided only when java2, they are not thread safe. So, when we lecture, we talk about the old ones first.
(2) data growth:
Both ArrayList and Vector have an initial capacity. When the number of elements stored in them exceeds the capacity, it is necessary to increase the storage space of ArrayList and Vector.
Add a memory unit, but add multiple memory units, each increase the number of memory units in the use of memory space and program efficiency to achieve a certain balance. The default growth of Vector is twice that of the original, while the growth strategy of ArrayList is not clearly stated in the documentation (1.5 times the growth seen from the source code). Both ArrayList and Vector can set the initial space size, and Vector can also set the amount of space for growth, while ArrayList does not provide a way to set the space for growth.
Summary: that is, the growth of Vector doubled and ArrayList increased by 0.5 times.
Thank you for reading! This is the end of the article on "what's the difference between ArrayList and Vector". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.