Java中的数组长度 [英] Array Length in Java
本文介绍了Java中的数组长度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我声明了一个数组,如下所示:
I declared an array as shown below:
int[] arr = new int[10];
然后我将以下值分配给数组:
Then I assigned following values to the array:
arr[0] = 1;
arr[1] = 2;
arr[2] = 3;
arr[3] = 4;
然后我声明并初始化了一个整数变量:
Then I declared and initialized an integer variable:
int arrayLength = arr.length;
这对于查找实际大小很有用,但是有什么方法可以找到数组的逻辑大小吗?
This will be useful to find actual size but is there any method to find logical size of the array?
推荐答案
它包含分配的大小,10
.未分配的索引将包含默认值,即 0
对于 int
.
It contains the allocated size, 10
. The unassigned indexes will contain the default value which is 0
for int
.
这篇关于Java中的数组长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文