一、代码
public static void main(String[] args) {
StopWatch stopWatch = new StopWatch();
stopWatch.start();
List<Integer> lists = new ArrayList<>();
for (int i = 0; i < 100000; i++) {
lists.add(i);
}
stopWatch.stop();
System.out.println("未指定集合大小=> " + stopWatch.getTotalTimeMillis() + " 毫秒");
StopWatch stopWatch1 = new StopWatch();
stopWatch1.start();
List<Integer> lists1 = new ArrayList<>(16);
for (int i = 0; i < 100000; i++) {
lists1.add(i);
}
stopWatch1.stop();
System.out.println("指定了集合大小=> " + stopWatch1.getTotalTimeMillis() + " 毫秒");
}
二、结果