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

How to understand the performance of List sets in Java

2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article introduces the knowledge of "how to understand the performance of List sets in Java". Many people will encounter such a dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

List is an ordered and repeatable collection of elements. each element in the collection has its corresponding sequential index. The List collection allows the use of repeating elements, and the collection elements at specified locations can be accessed through the index.

Var a=new ArrayList (); a.add (new String ("zxc")); System.out.println (a.indexOf (new String ("zxc")

In this code, the program tries to return the location of the zxc, but in fact List does not contain the string object, because new String is used when the List collection is added, but in the end the program still returns 1, because the two programs are compared to see if they are equal in List, only through equals

In the whole List series, ArrayList and LinkedList are typical implementations of linear tables: array-based linear tables and chain-based linear tables, Queue represents queues and Deque represents double-ended queues.

Generally speaking, because the array holds all array elements in a piece of continuous memory, the performance of the array is the best when it wants to be accessed randomly. All the internal collections with arrays as the underlying implementation perform better at random access, while the internal collections with linked lists as the underlying implementation have better performance when performing insert and delete operations, but generally speaking, ArrayList performs better than linkedList.

When traversing is needed, random access should be used for ArrayList,Vector and Iterator should be used for LinkedList.

If you need to perform inserts and deletes frequently, LinkedList is better because ArrayList and Vector need to allocate memory space frequently.

If multiple threads access elements in the List collection at the same time, consider wrapping the collection into a thread-safe collection through Collection

That's all for "how to understand the performance of List collections in Java". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

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