List classes in Java can be thought as resizable arrays. They are very frequently used as they are handy. In this part of the article, I'll show you two constructor tricks that can become quite useful in special cases. The first trick is for using an existing list content for creating a new list. The second trick is for ensuring the element capacity of a list. You can ask yourself why are we giving a capacity value to a list if it can increase its capacity by itself. The answer is that yes, lists can increase their capacity by themselves but if we know the potential size we can skip waiting for the initial capacity adjustment and save some precious time. Here's the code for constructor tricks:
40 | List<integer> list3 = new ArrayList<integer>(potentialSize); |
44 | for ( int i= 0 ; i < tmpinteger = " new" ></integer></integer></integer></integer></integer></integer> |