当前位置:网站首页>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
边栏推荐
- Four ways of SSH restricting login
- Tongxin UOS php7 2.3 upgrade to php7.0 two point two four
- flannel 原理 之 子网划分
- 在电视屏幕上进行debug调试
- man man随记和crontab的@reboot用法
- Quickly understand the three ways of thread implementation
- LLVM - 生成for循环
- 关于在vs中使用scanf不安全的问题
- DS1302的电子万年历_51单片机,年月日、星期、时分秒、农历和温度,带闹钟,全套资料
- ie8 浏览器提示是否 阻止访问js脚本
猜你喜欢

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

555定时器+74系列芯片搭建八路抢答器,30s倒计时,附Proteus仿真等

SHT11传感器的温度湿度监控报警系统单片机Proteus设计(附仿真+论文+程序等)

Use the executors class to quickly create a thread pool

流程控制之分支语句

Matlab Simulink modeling and design of single-phase AC-AC frequency converter, with MATLAB simulation, PPT and papers

Notes on Visio drawing topology

A blog allows you to learn how to write markdown on vscode

XX project structure notes

循环队列的基本操作,你学会了吗?
随机推荐
单片机的函数信号发生器,输出4种波形,频率可调,原理图,仿真和C程序
js 进度条,显示加载进度
AT89C52单片机的频率计(1HZ~20MHZ)设计,LCD1602显示,含仿真、原理图、PCB与代码等
ArrayList集合基本使用
js 递归(1)
LotusDB 设计与实现—1 基本概念
Parameter stack pressing problem of C language in structure parameter transmission
Logical volume creation and expansion
TUN 设备原理
JS recursion (1)
ssh限制登录的四种手段
The initial C language framework is suitable for review and preliminary understanding
顺序表的操作,你真的学会了吗?
逻辑卷创建与扩容
Flop effect
MCU function signal generator, output four kinds of waveforms, adjustable frequency, schematic diagram, simulation and C program
Processing MKDIR: unable to create directory 'AAA': read only file system
流程控制之分支语句
Introduction to the use of countdownlatch and cyclicbarrier for inter thread control
常见存储类型和FTP主被动模式解析
Now that you see this, why don't you give it a compliment before you go