How to populate the array without iterating it with known size and value?
Example: If I want to create an array of size 5 with values 1. I don't want to iterate with size 5 and use add method. Is there any other way?
How to populate the array without iterating it with known size and value?
Example: If I want to create an array of size 5 with values 1. I don't want to iterate with size 5 and use add method. Is there any other way?
int[] array = new int[5];
Arrays.fill(array, 1);
This should work.
i believe you can achieve that by following
int[] array = new int[5];
Arrays.fill(array, 0);
additionally you can check following link