看下面一段程序
List<String> list = new ArrayList<String>();
System.out.println(list.get(0));
这个会输出什么?
------------------------------
Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
下标越界异常。
原因:看了下get的API,
- IndexOutOfBoundsException - if the index is out of range ( index < 0 || index >= size())