Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Initializing an array after the declaration

Tags:

java

Why we cannot use array intializer after declaring an variable.

For example:

int arr[];
arr = {1,2,3,4};

But,

int arr[] = {1,2,3,4}; 

is correct. Is there any way to use array initialize after declaring an variable.

like image 943
Kaagesh Avatar asked Jul 17 '26 17:07

Kaagesh


1 Answers

This is how you can.

int arr[];

arr = new int[]{1, 2, 3, 4};
like image 120
Kashif Nazar Avatar answered Jul 19 '26 06:07

Kashif Nazar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!