Warning: fopen(/www/wwwroot/www.wendadaohang.com/data/md5_content_title/e0/e057085bee36b6fdd70e213b0737ab53.txt): failed to open stream: No space left on device in /www/wwwroot/www.wendadaohang.com/inc/function.php on line 2468

Warning: flock() expects parameter 1 to be resource, bool given in /www/wwwroot/www.wendadaohang.com/inc/function.php on line 2469

Warning: fclose() expects parameter 1 to be resource, bool given in /www/wwwroot/www.wendadaohang.com/inc/function.php on line 2475
java中怎么获得数组中的元素的个数 - 66问答网

java中怎么获得数组中的元素的个数

如题所述

java中知道数组中实际的元素个数的方法:
定义一个变量保存数组中的元素个数,然后对数组进行遍历,当数组元素不为空时,变量的值+1,否则不改变。
代码为:

1
2
3
4
5
6

int n = 0; //保存元素个数的变量
for(int i = 0; i < array.length; i++)
{
if(null != array[i]) n++;
}
System.out.println(n);
温馨提示:答案为网友推荐,仅供参考
第1个回答  2017-07-20
String a[]={"1","2","3"};
int b=a.length;
相似回答