工作中基本都用的map或者list,有時候突然需要用到數組 ,比如接受hql的查詢數據,讀取文件每行的數據,然而卻忘記咋聲明的了......
public static void main(String[] args) {
//創建數組的第一種方法
int[] arr=new int[6];
int intValue=arr[5];
//System.out.println(intValue);
//創建數組的第二種方法
int[] x={1,2,3,4};
//System.out.println(x[1]);
//創建數組的第三種方法。
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("數組標越界");
}
}
//判斷數組下標是否越界
public static boolean isLength(int m,int arr[]){
boolean flag=false;
int length = arr.length;
if(m<length)
flag=true;
return flag;
}