数组(静态初始化-常见问题)
2014-06-25 16:08
211 查看
class Demo1
{
public static void main(String[] args)
{
//数组的两种写法
int[] x = new int[2];
int[] y = new int[]{12,23};
//如果使用第一种的话,就要给他们赋值
x[0] = 12;
x[1] = 42;
System.out.println(x[1]+"+"+y[1]);
}
}
ArrayIndexOutOfBoundsException 操作数组是,访问到了数组中不存在的角标,角标越界异常
NullPointerException 空指针异常
class Demo2
{
public static void main(String[] args)
{
int[] x = new int[3];
System.out.println(x[3]);//显示ArrayIndexOutOfBoundsException 3
x = null;
System.out.println(x[1]);//显示NullPointerException
}
}
相关文章推荐
- C++中静态初始化数组与动态初始化数组详解
- (1)疯狂java:数据与内存的控制____数组初始化__1.1.1 java数组是静态的
- C语言静态数组的初始化
- 静态初始化数组由函数返回
- 数组的静态初始化
- 类的静态常量数组初始化
- Java--静态初始化一个数组
- C语言的静态数组初始化
- 如何在C++11中正确的初始化静态常量成员数组
- 【C语言的静态数组初始化】
- 黑马程序员——Java基础---- 数组(静态初始化_常见问题)(04)
- C++中静态初始化数组与动态初始化数组
- Java 数组的静态初始化和动态初始化
- [置顶] 静态初始化数组
- java数组,List,Set,Map动态和静态初始化
- stl 静态数组初始化vector及pair,vector混合使用
- java-数组静态初始化、选择排序、冒泡排序、数组的折半查找、折半查找练习
- 2013.12.29 静态初始化一个数组
- c语言中静态数组的定义和初始化
- 关于多维数组的静态初始化的分析[图结合程序说明]