我正在迭代列表的列表。在我的代码中 listofuserdetailsperAccount
是 List<List>
。我正在考虑以下两种方法,请告诉我哪种方法是正确的、更有效的并且在java编码中应该遵循。
方法一-----
for(int i=0;i<=listofuserdetailsperAccount.size();i++){
List list=(List) listofuserdetailsperAccount.get(0);
}
方法2---
for(int i=0;i<=listofuserdetailsperAccount.size();i++){
List list= new ArrayList();
list=(List) listofuserdetailsperAccount.get(0);
}
最佳答案
我会选择每个循环
for( List userDetailsPerAccount : listOfUserDetailsPerAccount ) {
//anything you want to do with userDetailsPerAccount
}
关于java - 下面代码中的列表迭代列表——哪种方法更好?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22928314/