We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Suppose 'a' is an array variable.. int [] a = {1,3,2,4}; It works.
int [] a = new float [12];
a = {1,3,2,4}
I adjust like that to reduce the use of memories.. but it has grammatical error.
In this case, how can I solve this problem?
Do I have to type one by one like a[1] =1; a[2] = 3; ... ?
Thanks.
Answers
Creating an array w/ just
{}
only works when we're also declaring its variable at the same time.Using that special syntax, an array's length is determined by the number of elements inside its
{}
.P.S.: We still can use
{}
after a variable has been declared.However, we need to fully specify the array's datatype this time:
Instead of declaration together w/ initialization: