Java: Initialize list with zeroes

Here's how:

List<Integer> list = Collections.nCopies(1337Desired number of zeroes, 0);


Note that nCopies returns an immutable list. To initialize for instance an ArrayList, use this:

List<Integer> list = new ArrayList<Integer>(Collections.nCopies(1337, 0));

Comments

Be the first to comment!