Initialize an ArrayList in Java
Published in
1 min readJul 22, 2019
How we initialize ArrayList in java
ArrayList is a class which extends AbstractList and implements the List interface. ArrayList supports dynamic arrays that can grow as needed.
Standard Java arrays are of a fixed length. After arrays are created, they cannot grow or shrink, which means that you must know in advance how many elements an array will hold.
- With add()
2. With Double Brace
3. With Shared Reference
4. From Array
5. From a Stream interface
6. From Immutable list factory method in java 9
the new factory methods for Collections introduced in Java 9 creating unmodified collections.
Hope this article help you a lots 🐵!