java怎样获取一维数组的长度?

来源:百度知道 编辑:UC知道 时间:2024/06/01 15:38:10
说详细点 元素个数
什么意思 不懂 据个例子行么

看看例子吧
public class Array {

public static void main(String[] args) {
int a[]={0,1,2,3,4,5}; //声明并初始化有6个元素的数组
int b=a.length; //得到数组的长度
System.out.println("数组a的长度为:"+b);
}

}

public class Demo {
public static void main(String[] args){
String[] array = {"求","数","组","的","长","度","!"};
int length = array.length;
System.out.println("数组array的长度为:" + length);
}
}

数组名.length()

用length()方法

.length()