kristain

博客园 首页 新随笔 联系 订阅 管理

2011年7月21日 #

摘要: 对List的遍历有三种方式 List<A> list = new ArrayList<A>(); list.add(new A()); list.add(new A()); ... 第一种: for(Iterator<A> it = list.iterator(); it.hasNext(); ) { .... } 这种方式在循环执行过程中会进行数据锁定, 性能稍差, 同时,如果你想在寻欢过程中去掉某个元素,只能调用it.remove方法, 不能使用list.remove方法, 否则一定出并发访问的错误. 第二种: for(A a : list) { ... 阅读全文
posted @ 2011-07-21 11:04 kristain 阅读(769) 评论(0) 推荐(1) 编辑