`

ArrayList添加add方法效率

 
阅读更多
public static void main(String args[]) {
		int count = 1000000;
		long start = System.currentTimeMillis();
		ArrayList<TestArrayList> test = new ArrayList<TestArrayList>();
		for (int i = 0; i < count; i++) {
			TestArrayList ts = new TestArrayList();
			test.add(ts);
		}
		long end = System.currentTimeMillis();
		System.out.println(end - start);

		long start2 = System.currentTimeMillis();
		ArrayList<TestArrayList> test2 = new ArrayList<TestArrayList>(count);
		for (int i = 0; i < count; i++) {
			TestArrayList ts2 = new TestArrayList();
			test2.add(ts2);
		}
		long end2 = System.currentTimeMillis();
		System.out.println(end2 - start2);
	}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics