Possible Duplicate:
list.clear() vs list = new ArrayList<int>();
I have a list:
List<Integer> l1 = new ArrayList<Integer>();
and added some integer variables on that list. After some operation, I need to reuse that list, so I set it to null.
Which is better, setting to null or using .clear()? Or is there another way?
If you set it to
null, then you have to initialize it again before using it. So I would just do:Which I think will be faster than calling
.clear()