现有List如下,内部有若干个成员, Size存储有width和height两个成员变量。
List<Size> l;
1. 常规访问方式
for(int i = 0; i < l.size(); i++){
Size s = l.get(i);
Log.e(TAG, s.width + "x" + s.height);
}
执行效率最高,但是内部不锁定,多线程情况下需考虑并发操作问题。
2. 增强型for循环
for(Size s : l){
Log.e(TAG, s.width + "x" + s.height);
}
内部实际调用了迭代器遍历,使用有限制,不建议使用。
3. 迭代器遍历
Iterator it = l.iterator();
while(it.hasNext()){
Size s = (Size)it.next();
Log.e(TAG, s.width + "x" + s.height);
}
执行过程中锁定数据,性能稍差。