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 the characteristics of ArrayList,Vector and LinkedList

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly explains "what are the characteristics of ArrayList,Vector and 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 are the characteristics of ArrayList,Vector and LinkedList"?

First of all, List and Set are similar, they are a collection of single-column elements, so they have a function common parent interface, called Collection. Duplicate elements are not allowed in Set, that is, there cannot be two objects that are equal (note, not just the same), that is, suppose there is an An object in the Set collection, and now I want to store another B object in the Set collection, but the B object is equal to the An object equals, then the B object cannot be stored, so the add method of the Set set has a boolean return value when there is no element in the set. When the add method can successfully join the element, it returns true. When the collection contains an element equal to the element equals, the add method cannot join the element, and the result is false. When Set fetches elements, it can't say which one. Instead, it can only get all the elements through the Iterator interface, and then iterate through each element one by one.

List means collections in order. Note that they are not sorted by age, size, price, and so on. When we call the add (Obj e) method many times, the objects added each time are sorted in the same first-come-first-served order as if there was a queue for buying tickets at the railway station. Sometimes, you can jump the queue by calling the add (intindex,Obj e) method to specify where the current object is stored in the collection. An object can be repeatedly stored in List, each time the add method is called, the object is inserted into the collection, in fact, not the object itself is stored in the collection, but in the collection with an index variable pointing to the object, when the object is add many times, that is, there are multiple indexes in the collection pointing to the object, as shown in figure x. In addition to getting all the elements through the Iterator interface and iterating through each element one by one, List can also call get (index I) to specify which one to take.

Map is different from List and Set, it is a two-column collection, in which there are put methods, defined as follows: put (obj key,obj value), each storage, to store a pair of key/value, can not store duplicate key, this repeated rule is also equal by equals. If you choose, you can get the corresponding value according to key, that is, the return value of get (Object key) is the value corresponding to key. In addition, you can get all the key combinations, you can get all the value combinations, and you can get a collection of Map.Entry objects composed of key and value.

List holds elements in a specific order, but there are repeating elements. Set cannot have repeating elements, internal sorting. Map saves key-value values, while value can have multiple values.

HashSet is stored according to some operation of the hashcode value, rather than directly according to the size of the hashCode value. For example, "abc"-> 78

The storage order of "def"-- > 62, "xyz"-- > 65 in hashSet is not 62Jing 6578. These questions are thanks to a former student named Cui Jian, and finally explain to him clearly by looking at the source code to see how many of the trainees can understand the source code. LinkedHashSet is stored in the order in which it is inserted, so what is the use of the hashcode method of the stored object? Students think! the hashset collection compares whether two objects are equal, first to see whether the hashcode method is equal, and then to see whether the equals method is equal. Insert two Student of new into HashSet, look at the size of HashSet, and then look at size after implementing the hashcode and equals methods.

The same object can be added to the Vector multiple times. Adding elements to the collection is equivalent to connecting the collection to the target object with a rope. It can't be added to HashSet many times.

Thank you for your reading, the above is the "ArrayList,Vector, what are the characteristics of LinkedList" content, after the study of this article, I believe you have a deeper understanding of the characteristics of ArrayList,Vector, LinkedList, the specific use of the need for you to practice and verify. 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

Development

Wechat

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

12
Report