What is the difference between following 2 approaches in creating an array.
Which is preferred depending on the use?
Approach 1:
int a[]= new int[5];
a[0] = 98;
a[1] = 97;
a[2] = 99;
a[3] = 94;
a[4] = 96;
Approach 2:
int a[]={98,97,99,94,96};
As far as I remember: the first one:
int a[]= new int[5];
creates 5 elements with a value of 0.
Then you’re assinging some values.
2nd approach directly assigns the values.
So the questions is: do you need that in-between situation having 5 elements with a value of 0 e.g. because you cannot assign all elements immediatly.