Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

java - Java String数组:有一个大小的方法吗?(Java String array: is there a size of method?)

I come from a php background and in php, there is an array_size() function which tells you how many elements in the array are used.

(我来自php背景,在php中,有一个array_size()函数,它告诉你数组中有多少元素被使用。)

Is there a similar method for a String[] array?

(String[]数组有类似的方法吗?)

Thanks.

(谢谢。)

  ask by phill translate from so

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

1 Answer

0 votes
by (71.8m points)

Yes, .length (property-like, not a method):

(是的, .length (类似属性,不是方法):)

String[] array = new String[10];
int size = array.length;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...