dangeroushai 2016-01-26 12:03 采纳率: 100%
浏览 1343
已采纳

求大神解答,先获取List再遍历与直接遍历的差别?

如:
for(Apple apple:plate.getApples()){
}

List list = plate.getApples();
for(Apple apple:list){
}
在执行效率上有区别吗?为什么?

  • 写回答

5条回答 默认 最新

  • threenewbee 2016-01-26 12:36
    关注

    你这么写完全是等价的,没有任何区别。因为list其实还是一个引用,而不是拷贝一份列表。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?