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

AT89C51 MCU digital voltmeter development, measuring range 0 ~ 5V, proteus simulation, schematic diagram, PCB and C program, etc

C语言知识点精细详解——初识C语言【1】——你不能不知的VS2022调试技巧及代码实操【2】

Detailed explanation of SAR command

C语言知识点精细详解——数据类型和变量【1】——进位计数制

Tongxin UOS php7 2.3 upgrade to php7.0 two point two four

C语言知识点精细详解——初识C语言【1】——你不能不知的VS2022调试技巧及代码实操【1】

基于TLC5615的多路可调数控直流稳压电源,51单片机,含Proteus仿真和C代码等

redis的五种数据类型

API Gateway/API 网关(二) - Kong的使用 - 负载均衡Loadbalance

AT89C51单片机的数字电压表开发,量程0~5V,proteus仿真,原理图PCB和C程序等
随机推荐
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)
初始c语言大致框架适合复习和初步认识
man man随记和crontab的@reboot用法
Proteus simulation design of four storey and eight storey elevator control system, 51 single chip microcomputer, with simulation and keil c code
顺序栈的基本操作
TLS/SSL 协议详解 (30) SSL中的RSA、DHE、ECDHE、ECDH流程与区别
进入新公司,运维工程师从下面这几项了解系统的部署
js 格式化时间
基于TLC5615的多路可调数控直流稳压电源,51单片机,含Proteus仿真和C代码等
统信UOS PHP7.2.3升级至PHP7.2.24
x509证书cer格式转pem格式
555定时器+74系列芯片搭建八路抢答器,30s倒计时,附Proteus仿真等
处理 mkdir:无法创建目录“aaa“:只读文件系统
Eight way responder system 51 Single Chip Microcomputer Design [with Proteus simulation, C program, schematic diagram, PCB files, component list and papers, etc.]
统信UOS卸载php7.2.24,安装php7.4.27 ;卸载再安装为PHP 7.2.34
KVM learning resources
Detailed explanation of C language P2 selection branch statement
On the insecurity of using scanf in VS
Web page, adaptive, proportional scaling
LM317的直流可调稳压电源Multisim仿真设计(附仿真+论文+参考资料)
Now that you see this, why don't you give it a compliment before you go