通过本地测试代码,发现java8的stream().forEach对liat集合循环,效率竟然不如之前的for循环
同样的代码,一百万条数据,直接上代码
public class Snippet
{
public static void main(String[] args)
{
List<Integer> filterLists = new ArrayList<>();
for(int i=0;i<1000000;i++)
{
filterLists.add(i);
}
Date a = new Date();
for(int j=0;j<1000000;j++)
{
System.out.println(filterLists.get(j));
}
Date b = new Date();
Date c = new Date();
filterLists.stream().forEach(s -> System.out.println(s));
Date d = new Date();
long interval = b.getTime()-a.getTime();
long interval2 = d.getTime()-c.getTime();
System.out.println("两个时间相差1:"+interval);//6602
System.out.println("两个时间相差2:"+interval2);//6824
}
}