How to set default value for items of List in Java?
We need a list if we need to change the size of list dynamically. If we don’t need dynamic size then an array is ideal in that case. If we want a list with initial values we can do it in multiple ways:
By using Collections.nCopies
Collection.nCopies is really handy in this use case.
Listlist = Collections.nCopies(10, 0);