当前位置:网站首页>Arrayslist method
Arrayslist method
2022-07-19 07:16:00 【INSIGNER】
ArraysList analysis
Arrays The underlying source code actually uses arrays , The initial size is 10. The reason why values can be stored indefinitely is : The capacity expansion mechanism in the array , When the number of arrays to be stored exceeds 10 when , It will automatically expand to save more values . The index uses ,
characteristic : High query efficiency , The efficiency of addition and deletion is low , Thread unsafe . More use .
High query efficiency : The method of directly using the index value of the array .
The efficiency of addition and deletion is low : Every time you add or delete, you will have a convenience .
Thread unsafe :( I can't explain it at the level of Xiaobian )
Writing a ArraysList:( For reference only )
public class ArraysTest<E> {
private Object[] list = new Object[10];
private int size = 0;
public void add(E e) {
size++;
for(int i =0; i < size;i++ ) {
if(list[i] == null) {
list[i] = e;
return;
};
append(e,size);
}
}
// When the size of the array is not enough, use this method to expand
private void append(E e,int size) {
Object[] temp = new Object[list.length+ (list.length>>1)];
int i1 = 0;
for( ; i1<list.length;i1++) {
temp[i1] = list[i1];
}
list = temp;
list[size + 1] = e;
}
// Add a value at the specified location
public void add(E e,int index) {
if(list[index] == null) {
size++;
list[index] = e;
}else {
System.out.println("There isn't null");
}
}
@Override
public String toString() {
System.out.print("[");
System.out.println("[");
for(int i = 0;i < size-1; i++) {
System.out.println(list[i]+",");
}
System.out.print(list[size-1]+"]");
return null;
}
// The value used to get the index position
public Object get(int index) {
if(list[index] != null) {
return list[index];
}else {
return " I'm sorry ! This value is not in the array ";
}
}
// Used to put a value at a specified position in the array
public void set(E e, int index) {
if(index <= list.length) {
list[index] = e;
}else if(index > list.length && index > (list.length+(list.length>>1))) {
append(e,index);
}else{
set(e,index);
}
}
}
边栏推荐
- 企业或个人域名备案怎么弄
- Use of urllib Library
- 快速理解重定向
- M based on the MIMO channel capacity analysis of MATLAB, different antenna numbers are compared; Non codebook precoding SVD, GMD; Codebook precoding DFT, TXAA and spatial diversity
- linux下执行shell脚本调用sql文件,传输到远程服务器
- 【无标题】
- 我的世界1.12.2 神奇宝贝(精灵宝可梦) 开服教程
- m基于matlab的MIMO信道容量分析,对比了不同天线数量;非码本预编码SVD,GMD;码本预编码DFT,TxAA以及空间分集
- 类与super、继承
- 网络知识-04 网络层-ICMP协议
猜你喜欢

Matlab simulation of cognitive femtocell performance in m3gpp LTE communication network

web安全(xss及csrf)

m基于matlab的DQPSK调制解调技术的仿真

Arm server building my world (MC) version 1.18.2 private server tutorial

9.账户和权限

TypeScript(ts-loader,tsconfig.json及lodash)

9. Account and authority

m基于MATLAB-GUI的GPS数据经纬度高度解析与kalman分析软件设计

字典、元组和列表的使用及区别,
![Minecraft整合包 [GTNH]格雷科技:新视野 服务器搭建教程](/img/59/d5f226f57cfd7d28d5a76ff38fae16.png)
Minecraft整合包 [GTNH]格雷科技:新视野 服务器搭建教程
随机推荐
Servlet 笔记
FreeBSD 12 domestic source speed up PKG and ports take a note
Quickly understand redirection
9. Account and authority
M based on the MIMO channel capacity analysis of MATLAB, different antenna numbers are compared; Non codebook precoding SVD, GMD; Codebook precoding DFT, TXAA and spatial diversity
WCDMA soft handoff performance matlab simulation m, comparing the average number of activation sets (MasN), activation set update rate (Asur) and call interruption probability (OP) three performance i
The principle of SYN Flood attack and the solution of SYN Flood Attack
Sword finger offer question brushing record - offer 05 Replace spaces
Review summary of MySQL
Matlab simulation of cognitive femtocell performance in m3gpp LTE communication network
How to set primary key self growth in PostgreSQL database
我的世界 1.18.1 Forge版 开服教程,可装MOD,带面板
网络知识-05 传输层-TCP
Pytorch learning diary (4)
字典,集合的使用,数据类型的转换
M analysis of anti-interference performance of high-speed frequency hopping communication system based on Simulink
Performance evaluation and comparison of Huawei cloud Kunpeng arm ECs and x86 ECS
M BTS antenna design based on MATLAB, with GUI interface
103.53.124.X IP段BGP线路和普通的专线有什么区别
5G时代服务器在这里面起着什么作用?