myList = Collections.nCopies(5, 0);
ListThis code creates a new list of size 3, containing three copies of the string "abc". In both examples, the nCopies method returns an immutable list, which means that the elements of the list cannot be modified. Therefore, we cannot add or remove elements from the list. Overall, nCopies method is a useful utility when we need to create an immutable list of a specific size, containing the same element. It is part of the Java.util Collections package library.
myList = Collections.nCopies(3, "abc");