当前位置:网站首页>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 )
边栏推荐
- #yyds干货盘点# 解决剑指offer:剪绳子(进阶版)
- 防火墙基础之华为华三防火墙web页面登录
- Pytorch learning 3 (test training model)
- [day 27] given an integer n, print out the full permutation from 1 to n | Full Permutation template
- 内网学习笔记(8)
- IJCAI 2022 | greatly improve the effect of zero sample learning method with one line of code. Nanjing Institute of Technology & Oxford proposed the plug and play classifier module
- Prometheus 2.26.0 new features
- 微服务如何拆分
- Hue new account error reporting solution
- Deploy redis sentinel mode using bitnamiredis Sentinel
猜你喜欢
随机推荐
每日刷題記錄 (六)
Crane: a new way of dealing with dictionary items and associated data
After 2 years of outsourcing, I finally landed! Record my ByteDance 3 rounds of interviews, hope to help you!
Pytorch learning 1 (learning documents on the official website)
夏日里的清凉
AXI總線
jvm 参数设置与分析
MySQL locking mechanism and four isolation levels
Explore tidb lightning source code to solve the found bugs
scrapy
万物互联时代到来,锐捷发布场景化无线零漫游方案
Axi bus
High efficiency exponentiation
防火墙基础之华为华三防火墙web页面登录
With the advent of the era of Internet of everything, Ruijie released a scenario based wireless zero roaming scheme
7 killer JS lines of code
Quick news: Huawei launched the Hongmeng developer competition; Tencent conference released the "Wanshi Ruyi" plan
Kotlin函数使用示例教程
快讯:华为启动鸿蒙开发者大赛;腾讯会议发布“万室如意”计划
mysql 锁机制与四种隔离级别


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






