list集合两种遍历效能比较
来源:互联网 发布:淘宝包包店铺简介 编辑:程序博客网 时间:2024/05/09 19:49
package test;import java.util.ArrayList;import java.util.List;public class EffectionTest{ public static void main(String[] args) { List<User> users = new ArrayList<User>(); int size = 100000; for(int i = 0; i < size; ++ i) { User user = new User(); user.setId(i); user.setName("name"+i); user.setPaw("paw"+i); user.setAdd("add"+i); users.add(user); } List<User> userList = new ArrayList<User>(); long beginTime = System.nanoTime(); //第一种 size 100000为 -----耗时7740654,7788548,7694470,7994950,7688198,7832452,7949907 for(User user : users) { userList.add(user); } long endTime = System.nanoTime(); System.out.println("The result is : " + (endTime - beginTime)); //第二种--- size 100000为-----耗时6057507,5750754,5776411,6040972,6042682,5881894,6055795// long beginTime = System.nanoTime();// for(int i = 0; i < users.size(); ++ i)// {// User user = users.get(i);// userList.add(user);// }// long endTime = System.nanoTime();// System.out.println("The result is : " + (endTime - beginTime)); }}class User{ Integer id; String name ; String paw; String add; /** * @return the id */ public Integer getId() { return id; } /** * @param id the id to set */ public void setId(Integer id) { this.id = id; } /** * @return the name */ public String getName() { return name; } /** * @param name the name to set */ public void setName(String name) { this.name = name; } /** * @return the paw */ public String getPaw() { return paw; } /** * @param paw the paw to set */ public void setPaw(String paw) { this.paw = paw; } /** * @return the add */ public String getAdd() { return add; } /** * @param add the add to set */ public void setAdd(String add) { this.add = add; } }总体来讲 推荐第二种遍历方式,速度快点。
0 0
- list集合两种遍历效能比较
- List集合两种遍历效率问题
- java中List集合的遍历和两种实现类的比较分析
- Java中List集合的遍历和两种实现类的比较分析
- java中List集合的遍历和两种实现类的比较分析
- java中List集合的遍历和两种实现类的比较分析
- list遍历效能测试和list分割
- 3、 004 List集合的两种遍历方法
- Map集合遍历的两种方式比较图解
- 集合框架_Map集合遍历的两种方式比较图解
- 在jsp页面遍历list集合时比较字符串
- list的四种遍历方式,遍历list集合
- Map集合的两种遍历方式
- 遍历Map集合的两种方式
- Map集合的两种遍历方式
- Map集合遍历的两种方式
- java集合Collection中的两种遍历
- 遍历List的两种方式
- 指针函数和函数指针
- 纯js写的分页
- Http请求
- 豪华版飞机大战系列(二)
- Android ActionBar完全解析,使用官方推荐的最佳导航栏(下)
- list集合两种遍历效能比较
- 简单插入排序
- 【培训专家访谈摘要】中小企业人才发展五大趋势]
- 王爱飞:电子商务如何借势DSP
- 什么是Bayer格式图像?
- Ubuntu KyLin 搭建单机版+伪分布式 Hadoop 1.2.1
- POJ 2739 Sum of Consecutive Prime Numbers
- 重载和覆盖
- NEON简介