再一次偶然的机会,看见了list.clear() 方法(ps:很少之前很少看API,只知道常用的,之后要准备看API了),觉得奇怪,便去深入源码研究了一下clear方法的特别之处。
个人之前在循环中要么是每次new一个list集合,要么就是使 list=null,但是在大批量大数据量循环的时候,确实影响性能的开销。
ArrayList 的 clear 方法源码如下:
/**
* Removes all of the elements from this list. The list will
* be empty after this call returns.
*/
public void clear() {
modCount++;
// clear to let GC do its work
for (</