当前位置:网站首页>Array related knowledge
Array related knowledge
2022-06-27 13:38:00 【There are fish in Beiming】
Array
1. The concept of array :
An array is a memory area used to store a batch of data of the same type ( Can be understood as a container ), Arrays are suitable for storing a batch of data of the same type
2. Static initialization of arrays :
Assign values to the array while defining the array variables
Format :
// Format 1
int[] a = new int[]{
1,2,3};
// Format 2
int[] a = {
1,2,3};
principle :
int[] ages = {
12,24,36};
Array variable name ages Save the address of array space in heap memory , So array variable names and index numbers can access array elements arr[0]
3. Dynamic initialization of arrays :
When defining an array, only determine the type of element and the length of the array , Then store the specific data
Format :
int[] a = new int[10];
principle :
Default value of element during dynamic initialization :
What are the differences between the characteristics and scenarios of the two arrays : The stored element value is already known , Initialize with static . It's not clear what data to store , Initialization with dynamic . The two formats are written independently , Do not mix .
5. Array access
Arrays are reference data types , Each element in the array can be accessed through the array variable name and index number
Access format : Array variable name [ Reference no. ]
Length of array : Array variable name .length
Maximum index of array : The length of the array -1( The premise is that the number of elements is greater than 0)
6. Traversal of array :
Traversal is to access the elements in the array one by one
Traversal format :
int[] a = {
1,2,3};
for(int i =0;i<a.length;i++){
System.out.println(a[i]);
}
7.Java Introduction to memory allocation :
Two array variables point to the same array :
8. Array considerations :
- An array type [] Array name Or you could write it as An array type Array name []
- What type of data does the array store , Otherwise, an error will be reported
- Once the array is defined , Program execution , length , The type is fixed
- If the accessed element position exceeds the maximum index , When it's executed ArrayIndexOutOfBoundsException( Array index out of bounds exception )
- If there is no address to store the array in the array variable , It is null, When accessing array information NullPointerException( Null pointer exception )
边栏推荐
- [XMAN2018排位赛]通行证
- 快速搭建一个自己的访问国外网站,搭建ss并开启bbr快速上网
- Pre training weekly issue 51: reconstruction pre training, zero sample automatic fine tuning, one click call opt
- Intranet learning notes (8)
- SFINAE
- [tcapulusdb knowledge base] Introduction to tcapulusdb tcapsvrmgr tool (III)
- OpenHGNN发布0.3版本
- AGCO AI frontier promotion (6.27)
- Vs debugging skills
- Record number of visits yesterday
猜你喜欢
[acwing] explanation of the 57th weekly competition
Cloud native (30) | kubernetes' app store Helm
【周赛复盘】LeetCode第81场双周赛
基于JSP实现医院病历管理系统
AGCO AI frontier promotion (6.27)
赛迪顾问发布《“十四五” 关键应用领域之数据库市场研究报告》(附下载)
Hue new account error reporting solution
What kind of air conditioner is this?
Implementation of recruitment website based on SSM
crane:字典项与关联数据处理的新思路
随机推荐
7 killer JS lines of code
【问题解决】Tensorflow中run究竟运行了哪些节点?
buuctf misc 百里挑一
CMOS level circuit analysis
手把手教你搭一个永久运行的个人服务器!
《预训练周刊》第51期:重构预训练、零样本自动微调、一键调用OPT
AXI總線
Explore tidb lightning source code to solve the found bugs
Kotlin函数使用示例教程
芯片供给过剩之际,进口最多的中国继续减少进口,美国芯片慌了
[acwing] explanation of the 57th weekly competition
Can flush open an account for stock trading? Is it safe?
MySQL locking mechanism and four isolation levels
enable_if
Pre training weekly issue 51: reconstruction pre training, zero sample automatic fine tuning, one click call opt
Journal quotidien des questions (6)
scrapy
[tcaplusdb knowledge base] Introduction to tcaplusdb tcapulogmgr tool (I)
PLM还能怎么用?
Axi bus