Which way is better for initializing a Java List:
-
new ArrayList<String>(futureSize) -
new ArrayList<String>(futureSize + 1)
(in order to prevent resizing of the list)
futureSize is the future size of the list once filled.
Note : If you are going to comment/answer anything about “premature optimizaton is…”, “you should instead…”, PLEASE DON’T. I am looking for an answer to my question, that’s all.
You can see from the implementation of
add(E e)and (similar methods)… that you should not run into trouble (i.e. the internal array is not resized) if you use