当前位置:网站首页>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
边栏推荐
- C语言知识点精细详解——数据类型和变量【2】——整型变量与常量【1】
- Introduction to the use of countdownlatch and cyclicbarrier for inter thread control
- MCU function signal generator, output four kinds of waveforms, adjustable frequency, schematic diagram, simulation and C program
- Some little records~
- Flop effect
- PWM speed regulation control system of DC motor based on 51 single chip microcomputer (with complete set of data such as Proteus simulation + C program)
- Qt实战:云曦聊天室篇
- Mq-2 and DS18B20 fire temperature smoke alarm system design, 51 single chip microcomputer, with simulation, C code, schematic diagram, PCB, etc
- Master in minutes --- ternary operator (ternary operator)
- C语言知识点精细详解——初识C语言【1】——你不能不知的VS2022调试技巧及代码实操【2】
猜你喜欢
Processing MKDIR: unable to create directory 'AAA': read only file system
Matlab Simulink modeling and design of single-phase AC-AC frequency converter, with MATLAB simulation, PPT and papers
51 MCU + LCD12864 LCD Tetris game, proteus simulation, ad schematic diagram, code, thesis, etc
sar命令详解
After entering the new company, the operation and maintenance engineer can understand the deployment of the system from the following items
本以为能躺着进华为,结果陆续收到京东/滴滴/爱奇艺offer的我迷茫了
Detailed explanation of SAR command
51单片机的直流电机PWM调速控制系统(附Proteus仿真+C程序等全套资料)
DS1302的电子万年历_51单片机,年月日、星期、时分秒、农历和温度,带闹钟,全套资料
OpenFaaS实战之四:模板操作(template)
随机推荐
API Gateway/API 网关(二) - Kong的使用 - 负载均衡Loadbalance
Docker (V) MySQL installation
网页自适应,等比缩放
KVM learning resources
c语言在结构体传参时参数压栈问题
Introduction to the use of countdownlatch and cyclicbarrier for inter thread control
Use cases of the arrays class
Qt界面优化:鼠标双击特效
Nacos uses demo as configuration center (IV)
Web page, adaptive, proportional scaling
Quickly understand the three ways of thread implementation
翻牌效果
man man随记和crontab的@reboot用法
xx项目架构随记
交通灯系统51单片机设计(附Proteus仿真、C程序、原理图及PCB、论文等全套资料)
js 抛物线运动方法封装
LLVM - 生成局部变量
LotusDB 设计与实现—1 基本概念
JumpServer
redis 模块编程中 key value的生命周期