Java – How to set a default value for items list

java

I'm trying to convert some python code to java and need to setup a default value of a list. I know the default value, the size of the list and my goal is to setup a default value and then later in my program change them. In python I simply do this(to create 10 items with a value of zero):

list = [0]*10  

I am trying to do:

List<Integer> list1 = Arrays.asList(0*10); // it just multiples 0 by 10.

It doest work, I know I can do something like this:

for(int i = 0;i<10;i++)
{
  list1.add(0); 
}

I was wondering if there was an better way(instead of the for loop)?

Best Solution

Arrays.fill lets you avoid the loop.

Integer[] integers = new Integer[10];
Arrays.fill(integers, 0);
List<Integer> integerList = Arrays.asList(integers);