当前位置:网站首页>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 )
边栏推荐
- What is low code for digital Nova? What is no code
- 微服务如何拆分
- hue新建账号报错解决方案
- Can flush open an account for stock trading? Is it safe?
- Shake hands with life and make peace
- Cool in summer
- Interviewer: do you understand redis' shared object pool?
- Number of printouts (solved by recursive method)
- PLM还能怎么用?
- 基于JSP实现医院病历管理系统
猜你喜欢
随机推荐
创建Deployment后,无法创建Pod问题处理
Summary and Thinking on interface test automation
如何使用200行代码实现Scala的对象转换器
mysql 锁机制与四种隔离级别
【问题解决】Tensorflow中run究竟运行了哪些节点?
Awk concise tutorial
Read a poem
一次性彻底解决 Web 工程中文乱码问题
昨天访问量破记录
全球芯片市场或陷入停滞,中国芯片逆势扩张加速提升自给率
How to use 200 lines of code to implement Scala's Object Converter
爱可可AI前沿推介(6.27)
crane:字典项与关联数据处理的新思路
Today's sleep quality record 78 points
Summary of redis master-slave replication principle
基于SSM实现招聘网站
Hardware development notes (VII): basic process of hardware development, making a USB to RS232 module (VI): creating 0603 package and associating principle graphic devices
A method to realize automatic renaming of pictures uploaded by WordPress
打印输出数(递归方法解决)
Pytorch learning 3 (test training model)


![[dynamic programming] - Knapsack Problem](/img/27/c48284f15e3f80305d7ce7c02d4378.png)





