这两种方法,那种效率更高呢? 说明:已发一类似贴,http://topic.csdn.net/u/20090529/17/69e63b93-a9db-4612-961b-c9c57c0ddfb4.html?seed=358121370,为能有更多人参与,再发一个标题好点的吧. 方法1: List <User> userList = getUserList(); for (User user : userList) { System.out.println(user.getUserid); }
方法2: List userList = (ArrayList)getUserList(); for (int i=0;i < userList.length; i++) { User user = (User)userList.get(i); System.out.println(user.getUserid); }
这个是最好的: List userList = (ArrayList)getUserList(); for (int i=0, k = userList.length;i < k; i++) { User user = (User)userList.get(i); System.out.println(user.getUserid); }