Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
179 views
in Technique[技术] by (71.8m points)

java - Java中的数组长度(Array Length in 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?

(这对于查找实际大小很有用,但有没有找到数组逻辑大小的方法?)

  ask by Kiran Bhat translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

It contains the allocated size, 10 .

(它包含分配的大小, 10 。)

The unassigned indexes will contain the default value which is 0 for int .

(未分配的索引将包含默认值,对于int ,该值为0 。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...