What is the difference between multiple implementations of ArrayList in the (Java8) source code
arraylist, java, java-8
Solution
Actually its there ever since `Arrays.asList()` introduced. Array's ArrayList is view of the underlying array. If the Array gets changed the ArrayList will get effected and viceversa.
The main benefit, No additional space required because it wont copy the array to a new object (ArrayList), also no additional time to copy the elements.
Problem
I was trying to understand `Stream`s in Java8 and intermittently I stumbled upon an interesting thing in the source code of Java8: `ArrayList` seems to be implemented twice: The obvious one: `java.util.ArrayList` The non-obvious one: `java.util.Arrays.ArrayList`, which is a private class. One odd difference is that the normal version is way bigger, and implements `List<E>`, whereas `Arrays.ArrayList` does not do so (directly). Why is it defined twice? And why with the same name?