当前位置:网站首页>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 )
边栏推荐
- Hue new account error reporting solution
- 创建Deployment后,无法创建Pod问题处理
- What else can PLM do?
- [XMAN2018排位赛]通行证
- Pre training weekly issue 51: reconstruction pre training, zero sample automatic fine tuning, one click call opt
- POSIX AIO -- Introduction to glibc version asynchronous IO
- Using FRP tool to realize intranet penetration
- 使用bitnamiredis-sentinel部署Redis 哨兵模式
- 打印输出数(递归方法解决)
- JVM parameter setting and analysis
猜你喜欢

Realization of hospital medical record management system based on JSP
![[tcaplusdb knowledge base] Introduction to tcaplusdb tcapulogmgr tool (I)](/img/ce/b58e436e739a96b3ba6d2d33cf8675.png)
[tcaplusdb knowledge base] Introduction to tcaplusdb tcapulogmgr tool (I)

高效率取幂运算

Half find (half find)
![[acwing] explanation of the 57th weekly competition](/img/ef/be89606b0e7fffac08280db0a73781.gif)
[acwing] explanation of the 57th weekly competition

How to set postman to Chinese? (Chinese)

Deep understanding of bit operations

隐私计算FATE-离线预测

Privacy computing fat offline prediction

类模板中可变参的逐步展开
随机推荐
Does Xinhua San still have to rely on ICT to realize its 100 billion enterprise dream?
对半查找(折半查找)
Summary and Thinking on interface test automation
基于JSP实现医院病历管理系统
Yuweng information, a well-known information security manufacturer, joined the dragon lizard community to build an open source ecosystem
EventLoop learning
Type 'image' is not a subtype of type 'imageprovider < object > solution
Teach you how to build a permanent personal server!
JVM parameter setting and analysis
Good luck today
Yyds dry goods inventory solution sword finger offer: cut rope (advanced version)
高效率取幂运算
Using FRP tool to realize intranet penetration
mysql 锁机制与四种隔离级别
ensp云朵配置
Shake hands with life and make peace
Tiktok practice ~ public / private short video interchange
How to choose LAN instant messaging software
Quickly set up a website to visit foreign countries, set up SS and start BBR to quickly surf the Internet
JVM performance tuning and monitoring tools -- JPS, jstack, jmap, jhat, jstat, hprof