Java数组操作
声明数组
1
2
3
4String[] arr1;
String arr2[];
String arr3[] = new String[5];
String[] arr4 = new String[5]初始化数组
1
2
3
4
5
6
7
8
9
10// 静态初始化
String[] arr1 = {"1", "2", "3", "4", "5"};
String[] arr1 = new String[]{"1", "2", "3", "4", "5"};
String arr2[] = new String[]{"1", "2", "3", "4", "5"};
String arr2[] = {"1", "2", "3", "4", "5"};
// 动态初始化
int score[] = new int[3];
for (int i = 0; i < score.length; i++) {
score[i] = i + 1;
}查看数组的长度
1
int length = arr.length;
遍历数组
1
2
3for (int i = 0; i< arr.length; i++) {
}int 数组转成string数组
1
2
3int[] arr = {1, 2, 3, 4, 5};
String arrStrings = Arrays.toString(arr);
System.out.println(arrStrings);从array中创建ArrayList
1
2
本文作者 : Xuebin Zhang
原文链接 : https://capping.github.io/2018/10/30/Java-Array/
版权声明 : 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明出处!