当前位置:网站首页>ArrayList collection basic usage
ArrayList collection basic usage
2022-04-23 14:27:00 【Zinksl】
Personal introduction
Hello, I'm : A pine
Seriously share technology , Record what you learn
If sharing is useful to you, please support me
give the thumbs-up : Leaving a message. : Collection :️
Personal motto : The best time to implement an idea is now !
List of articles
Collection Overview
aggregate , Containers of variable length
1 ArrayList Set variable length principle :
- ArrayList aggregate : So is the underlying principle , Array ; The initial size length is 10
1 Initializes a length of 10 Array of , The values are stored in sequence , When the storage space of the array is not enough, enter the second link ;
2 Create an original array length 1.5 A new array of multiples , Copy the contents of the original array to the new array , Then the data not saved in the first link , Save to new array ;
Be careful : Selection of sets and arrays 【 The length remains unchanged, using an array , Set with variable length 】
2 ArrayList aggregate
- ArrayList Tectonics 1
- public ArrayList();
- Generic :<>
- Add... After the class name <>, Can make the data type stored in the collection , Make type restrictions ;
- Only reference data types can be used in angle brackets , Cannot be a basic data type
Solution :【 Basic types have corresponding wrapper classes 】
Basic data type | Corresponding packaging |
---|---|
int | Integer |
short | Short |
byte | Byte |
double | Double |
float | Float |
char | Character |
3 ArrayList Common member methods
- increase
- public boolean add(E e); Add data to the tail of the collection , Return the status of successful addition
- public void add(int index,E element); Queue jumping and adding
ArrayList<String> list1 = new ArrayList<>();// establish list aggregate
list1.add(" Zhang San "); // Additive elements
- Delete
- public E remove(int index); Delete the elements in the collection according to the index
- public boolean remove( Elements ); Delete the contents of the collection according to the elements , Duplicate elements delete only the first ; Return the status of successful addition
ArrayList<String> list1 = new ArrayList<>();// establish list aggregate
list1.add(" Zhang San "); // Additive elements
list1.add(" Wang Wu ");
list1.add(" Shangguan iron egg ");
list1.add(" Zhang San ");
list1.add(" Zhuge order ");
list1.remove(" Zhang San "); // Delete according to the element
list1.remove(2); // Delete the element according to the index value
- Change
- public E set(int index,E element); Modify the specified index location , Returns the overwritten element
ArrayList<String> list1 = new ArrayList<>();// establish list aggregate
list1.add(" Zhang San "); // Additive elements
list1.add(" Wang Wu ");
list1.add(" Shangguan iron egg ");
list1.add(" Zhang San ");
list1.add(" Zhuge order ");
list1.set(2," Yearly salary one million "); // Modify set data
- check
- public E get(int index); Index based , Get the elements in the collection
ArrayList<String> list1 = new ArrayList<>();// Create set
list1.add(" Zhang San "); // Additive elements
list1.add(" Wang Wu ");
list1.add(" Shangguan iron egg ");
list1.add(" Zhang San ");
list1.add(" Zhuge order ");
list1.get(2); // Find set elements
4 ArrayList Set basic cases
4.1 Case study 1
Create a collection of stored strings , Storage 5 String elements , find 4 One word name , And print
public static void main(String[] args) {
ArrayList<String> list1 = new ArrayList<>();// establish list aggregate
list1.add(" Zhang San "); // Additive elements
list1.add(" Wang Wu ");
list1.add(" Shangguan iron egg ");
list1.add(" Zhang San ");
list1.add(" Zhuge order ");
for (int i = 0; i < list1.size(); i++) {
// Ergodic set
String name = list1.get(i); // Get collection elements
if (list1.get(i).length()==4){
// Determine if the string length is 4
System.out.println(name); // Print 4 The name of a word
}
}
}
Conclusion
Boss, please stay
Now that you see this, why don't you give it a compliment before you go
The purpose of this article is to share the technology and the points that should be paid attention to in the learning process , Record the learning process ;
If there are mistakes, you are welcome to correct , If you have any comments or suggestions, please discuss them in the comment area
版权声明
本文为[Zinksl]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231412046073.html
边栏推荐
- bc的用法
- A blog allows you to learn how to write markdown on vscode
- Use the executors class to quickly create a thread pool
- Web page, adaptive, proportional scaling
- 基于单片机的DS18B20的数字温度监控报警系统设计【LCD1602显示+Proteus仿真+C程序+论文+按键设置等】
- Docker (V) MySQL installation
- Gif to still image processing
- 循环队列的基本操作,你学会了吗?
- Redis cluster 原理
- js 递归(1)
猜你喜欢
Multisim Simulation Design of DC adjustable regulated power supply of LM317 (with simulation + paper + reference)
Proteus simulation design of DC adjustable regulated power supply (with simulation + paper and other data)
API Gateway/API 网关(三) - Kong的使用 - 限流rate limiting(redis)
Notes on Visio drawing topology
Design of single chip microcomputer Proteus for temperature and humidity monitoring and alarm system of SHT11 sensor (with simulation + paper + program, etc.)
数组模拟队列进阶版本——环形队列(真正意义上的排队)
AT89C52单片机的频率计(1HZ~20MHZ)设计,LCD1602显示,含仿真、原理图、PCB与代码等
本以为能躺着进华为,结果陆续收到京东/滴滴/爱奇艺offer的我迷茫了
LM317的直流可调稳压电源Multisim仿真设计(附仿真+论文+参考资料)
51单片机+LCD12864液晶显示的俄罗斯方块游戏,Proteus仿真、AD原理图、代码、论文等
随机推荐
矩阵交换行列
xx项目架构随记
Master in minutes --- ternary operator (ternary operator)
Matrix exchange row and column
Redis cluster 原理
Some little records~
51 MCU + LCD12864 LCD Tetris game, proteus simulation, ad schematic diagram, code, thesis, etc
单片机的函数信号发生器,输出4种波形,频率可调,原理图,仿真和C程序
Upgrade of openssh and modification of version number
Introduction to the use of semaphore for inter thread control
SSH 通过跳板机连接远程主机
直流可调稳压电源的Proteus仿真设计(附仿真+论文等资料)
AT89C51单片机的数字电压表开发,量程0~5V,proteus仿真,原理图PCB和C程序等
flannel 原理 之 子网划分
Sed learning for application
SHT11传感器的温度湿度监控报警系统单片机Proteus设计(附仿真+论文+程序等)
Tongxin UOS php7 2.3 upgrade to php7.0 two point two four
爬虫练习题(一)
单相交交变频器的Matlab Simulink建模设计,附Matlab仿真、PPT和论文等资料
Use cases of the arrays class