1. 程式人生 > >遍歷List的兩種方式

遍歷List的兩種方式

public void list1(List list) {
		long l1 = System.currentTimeMillis();
		for (String string : list) {
			System.out.println(string);
		}
		System.out.println(System.currentTimeMillis() - l1);
	}

	public void list2(List list) {
		long l1 = System.currentTimeMillis();
		Iterator it = list.iterator();
		while (it.hasNext()) {
			String str = it.next();
			System.out.println(str);
		}
		System.out.println(System.currentTimeMillis() - l1);
	}