Collection-Exception
public class _Exception {
public static void main(String[] args) {
//TODO Collection Exception
//TODO ArrayList list = new ArrayList(-1); => IllegalArgumentException 非法容量
ArrayList list = new ArrayList(10);
list.add("a");
list.add("b");
list.add("c");
//TODO list.get(3); => IndexOutOfBoundsException 访问索引越界
//如果访问的集合是数组,那么索引的范围是 0 到 数组长度-1
//如果访问的集合是List,那么索引的范围是 0 到 数据长度-1 => 底层数组有空间但无数据的不能访问
LinkedList list1 = new LinkedList();
//TODO list1.getFirst(); => NoSuchElementException 访问数据不存在
HashMap map = new HashMap();
map.put("a","1");
map.put("b","2");
map.put("c","3");
//TODO ConcurrentModificationException 遍历过程中修改数据 => 数据不一致 -- 迭代器解决
// for (Object o : map.keySet()) {
// if ("b".equals(o)) {
// map.remove(o); 或 map.put
// }
//
// System.out.println(map.get(o));
// }
}
}