当前位置:网站首页>[HBZ share] reasons for slow addition and deletion of ArrayList and fast query
[HBZ share] reasons for slow addition and deletion of ArrayList and fast query
2022-07-06 04:21:00 【hbz-】
ArrayList When is the query fast ?
- Only by subscript index When inquiring , Very fast performance , Because you can directly find the corresponding data in the following table , Time complexity O(1)
- When non subscript query , But through for Loop to traverse , The performance is not fast , Time complexity O(n)
- myth : Many people mistakenly think ArrayList Any inquiry is fast , It's actually wrong , Only through index Our inquiry is very fast
ArrayList Why the increase of performance is slow
- In image ArrayList Add elements to add When , Could lead to List Expansion of , because ArrayList The bottom layer is array structure , But the data does not support dynamic expansion , therefore ArrayList The capacity expansion mechanism of is to create a new array , Migrate the array data to the new array , Then add new elements
- The expansion mechanism is , If the original array does not exist , And expand the capacity directly 10 individual . If the original array exists , Then expand 1.5 By , namely oldSize + oldSize >> 1
ArrayList Why is the deletion performance slow
- Deletes the specified element ,ArrayList The bottom layer is actually deleted from index The position is the starting point , All elements to the last , Move one bit forward , Then set the last bit to null
- Move all elements , In fact, it is through the bottom System.arraycopy(), The array of index+1 Position start , Copied to the index Location , Then the last one =null
- So the process will be slow
ArrayList Modification of
- Modification is the same as query , When specifying index when , Directly modifying , A high performance O(1)
- When the cycle for To modify , Then the performance is low O(n)
边栏推荐
- R note prophet
- Class A, B, C networks and subnet masks in IPv4
- Le compte racine de la base de données MySQL ne peut pas se connecter à distance à la solution
- asp. Core is compatible with both JWT authentication and cookies authentication
- 10 exemples les plus courants de gestion du trafic istio, que savez - vous?
- 2327. Number of people who know secrets (recursive)
- MySql數據庫root賬戶無法遠程登陸解决辦法
- Viewing and verifying backup sets using dmrman
- Mysql数据库慢sql抓取与分析
- 10個 Istio 流量管理 最常用的例子,你知道幾個?
猜你喜欢

Fundamentals of SQL database operation

Data processing methods - smote series and adasyn

Basic use of MySQL (it is recommended to read and recite the content)

Stable Huawei micro certification, stable Huawei cloud database service practice

Jd.com 2: how to prevent oversold in the deduction process of commodity inventory?

Patent | subject classification method based on graph convolution neural network fusion of multiple human brain maps
![[Zhao Yuqiang] deploy kubernetes cluster with binary package](/img/45/6777fa919386e526dbb0d2c808a7f2.jpg)
[Zhao Yuqiang] deploy kubernetes cluster with binary package

Stack and queue

Tips for using dm8huge table

coreldraw2022新版本新功能介绍cdr2022
随机推荐
Hashlimit rate control
The value of two date types is subtracted and converted to seconds
Class A, B, C networks and subnet masks in IPv4
When debugging after pycharm remote server is connected, trying to add breakpoint to file that does not exist: /data appears_ sda/d:/segmentation
Sentinel sliding window traffic statistics
P2102 floor tile laying (DFS & greed)
Python book learning notes - Chapter 09 section 01 create and use classes
C. The third problem
. Net interprocess communication
Web components series (VII) -- life cycle of custom components
coreldraw2022新版本新功能介绍cdr2022
One question per day (Mathematics)
NPM command -- install dependent packages -- Usage / explanation
Lombok principle and the pit of ⽤ @data and @builder at the same time
绑定在游戏对象上的脚本的执行顺序
Easyrecovery靠谱不收费的数据恢复电脑软件
1291_Xshell日志中增加时间戳的功能
CADD课程学习(7)-- 模拟靶点和小分子相互作用 (柔性对接 AutoDock)
pd. to_ numeric
Yyds dry goods inventory web components series (VII) -- life cycle of custom components