I was trying to make a program where there is a need to take an extra size of array than the actual number of elements. I was able to do it using traditional way of assigning the element one by one
int[] arr = new int[7];
arr[0] = 2;
arr[1] = 5;
arr[2] = 1;
arr[3] = 3;
arr[4] = 8;
arr[5] = 9;
I was able to do it successfully via this method, but is there any way in array where I can perform this task in a single line i.e. to declare the size and initialise in a single line
Something like following
int[] arr = new int[7]{2, 5, 1, 3, 8, 9};
or similar to this
int[] arr = new int[7];
arr = {2, 5, 1, 3, 8, 9};