当前位置:网站首页>数组相关的知识点
数组相关的知识点
2022-07-28 10:28:00 【jjj34】
一.静态数组
1. .length
获取长度
int[] nums = new int [13];
int n = nums.length;二维数组
int rowlength=nums.length; // 行数
int collength = nums[0].length; //列数2.默认赋值
int -> 0
boolean -> false
3.声明
int[] name = new int [size];4.空数组为
new int [0];
输出结果:[]
二.动态数组
1.声明
ArrayList<Integer> name = new ArrayList<>();2.获取长度
int n = name.size();
3.判断是否为空
name.isEmpty();4.添加元素
(1) 不带索引
name.add(1) 默认添加在尾部
(2) 带索引
name.add(1,2) 在索引值为1的地方添加25.输出
System.out.println(name)
将会把数组中的所有元素输出,如
[1,1]6.判断数组中是否包含某个数
name.contains(n); n就是被判断的数7.移除数
name.remove(n) 移除索引值为n的数8.修改数
name.set(n,k) 将索引值为n的值修改为k9.访问数组元素
name.get(2) 访问索引值为2的值10.通过值找到索引
name.indexOf(n);
如果n存在就返回 n 的索引值,不存在就返回 -111.清除动态数组的所有值
name.clear();12.拼接两个动态数组
l1 [1,2,3]
l2 [5,6]
l1.addAll(l2);
l1 [1,2,3,5,6]边栏推荐
- SDUT 2446 最终排名
- [application of stack] - infix expression to suffix expression
- Django celery redis send email asynchronously
- ACM winter vacation training 4
- 机器人技术(RoboCup 2D)实验五十题及主要函数含义
- SDUT Round #9 2020-新春大作战
- 10_ UE4 advanced_ Add fall and cast actions
- 蓝桥杯嵌入式-HAL库-ADC
- 7、MapReduce自定义排序实现
- Qt生成.exe文件 并 在无Qt环境下运行(Enigma Virtual Box进行绿色可执行软件封装)图文教程
猜你喜欢
随机推荐
网络文件系统服务(NFS)
2020 second intelligence cup preliminaries
Django celery redis send email asynchronously
GKSpheresNoiseSource
PyQt5快速开发与实战 4.11 拖曳与剪贴板
GKNoiseSource
20200229 training race L2 - 2 tree species Statistics (25 points)
Batch Normlization
10_ UE4 advanced_ Add fall and cast actions
GKCheckerboardNoiseSource
GKCircleObstacle
11_ue4进阶_男性角色换成女性角色,并修改动画
samba学习
QT generation Exe file and run without QT environment (enigma virtual box for green executable software packaging) graphic tutorial
Codeforces Round #614 (Div. 2) A. ConneR and the A.R.C. Markland-N
GKCylindersNoiseSource
蓝桥杯嵌入式-HAL库-ADC
6. MapReduce custom partition implementation
C language input string with spaces
GKSpheresNoiseSource









