Interview Question
Developer Program EngineersTeam: Yandex
Country: Russia
Interview Type: Written Test
There are two optimizations depending on the scenario. If you know the specific type of data the container would hold, you should identify that generic using the <> syntax. Secondly, if you know this list will be holding some large amount of data (more than the default 10 that are declared) you could go ahead and allocated that with the constructor and provide an initial size to more closely reflect your array's needs. This will prevent unnecessary resizing and recopying as the arraylist is loaded.
As i understood from question....
- Sharma October 03, 20131. Make ArrayList as generic type.
2. Change default capacity to user defined capacity.
3. Default capacity is 10 you can change and make it 1.
i.e. ArrayList<E> list = new ArrayList<E>(1).
Please make comment if i misunderstood the problem.