Java中创建数组的几种方法
Java中創(chuàng)建數(shù)組的幾種方法
public static void main(String[] args) {
//創(chuàng)建數(shù)組的第一種方法
int[] arr=new int[6];
int intValue=arr[5];
//System.out.println(intValue);
//創(chuàng)建數(shù)組的第二種方法
int[] x={1,2,3,4};
//System.out.println(x[1]);
//創(chuàng)建數(shù)組的第三種方法。
int[] y= new int[]{1,2,3,4,5};
int m=0;
boolean length = isLength(m,y);
if(length){
System.out.println(y[m]);
}else{
System.err.println("數(shù)組標(biāo)越界");
}
}
//判斷數(shù)組下標(biāo)是否越界
public static boolean isLength(int m,int arr[]){
boolean flag=false;
int length = arr.length;
if(m<length)
flag=true;
return flag;
}
原文博客的鏈接地址:https://cnblogs.com/qzf/
轉(zhuǎn)載于:https://www.cnblogs.com/qianzf/p/6889044.html
總結(jié)
以上是生活随笔為你收集整理的Java中创建数组的几种方法的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: SVN使用规范
- 下一篇: UEM用户行为了如指掌!