Why 2 signature for declaring array variable in Java?

Java
1) int[] arr;
2) int arr[];

C and C++
1) int i[];

Q) what is the logic behind allowing the programmers of Java to write "[]" with type as well as variable name?


A) Readability. The answer is Readability.
Read the following from left to right.

int arr[5];


I am creating an int variable "arr" of size 5. oh! it means i am creating an array of size 5 and type int.
Right ???

Now, Read the following from left to right.

int[] arr=new int[5];

I am creating an int array variable "arr" of size 5.

WOW!!!! This is so simple to read & understand. isn't it ?

Comments

Popular posts from this blog

Hashicorp Configuration Language - HCL

Terraform - Input Variables

Terraform - Tainting and Updating Resources