当前位置:网站首页>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
边栏推荐
猜你喜欢

Notes on Visio drawing topology

TUN 设备原理

Processing MKDIR: unable to create directory 'AAA': read only file system

OpenFaaS实战之四:模板操作(template)

c语言在结构体传参时参数压栈问题

Electronic perpetual calendar of DS1302_ 51 single chip microcomputer, month, day, week, hour, minute and second, lunar calendar and temperature, with alarm clock and complete set of data

统信UOS PHP7.2.3升级至PHP7.2.24

Man man notes and @ reboot usage of crontab

数组模拟队列进阶版本——环形队列(真正意义上的排队)

51 Single Chip Microcomputer Design of traffic light system (with Proteus simulation, C program, schematic diagram, PCB, thesis and other complete data)
随机推荐
Use cases of the arrays class
Parameter stack pressing problem of C language in structure parameter transmission
SSH 通过跳板机连接远程主机
51单片机的花卉、农田自动浇水灌溉系统开发,Proteus仿真,原理图和C代码
一篇博客让你学会在vscode上编写markdown
基于TLC5615的多路可调数控直流稳压电源,51单片机,含Proteus仿真和C代码等
交通灯系统51单片机设计(附Proteus仿真、C程序、原理图及PCB、论文等全套资料)
Redis源码分析之PSYNC同步
Introduction to the use of semaphore for inter thread control
Mq-2 and DS18B20 fire temperature smoke alarm system design, 51 single chip microcomputer, with simulation, C code, schematic diagram, PCB, etc
JS recursion (1)
TUN 设备原理
MCU function signal generator, output four kinds of waveforms, adjustable frequency, schematic diagram, simulation and C program
LM317的直流可调稳压电源Multisim仿真设计(附仿真+论文+参考资料)
Electronic scale weighing system design, hx711 pressure sensor, 51 single chip microcomputer (proteus simulation, C program, schematic diagram, thesis and other complete data)
Debug on TV screen
kprobe 的 3 种使用
LLVM - 生成加法
source insight via samba
微信小程序将原生请求通过es6的promise来进行优化
Now that you see this, why don't you give it a compliment before you go