Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java: int[] array vs int array[] [duplicate]

Is there a difference between

int[] array = new int[10]; 

and

int array[] = new int[10]; 

?

Both do work, and the result is exactly the same. Which one is quicker or better? Is there a style guide which recommends one?

like image 958
xuma202 Avatar asked Jan 28 '13 10:01

xuma202


People also ask

What is the difference between int array [] and int [] array?

What is the difference between int[] a and int a[] in Java? There is no difference in these two types of array declaration. There is no such difference in between these two types of array declaration. It's just what you prefer to use, both are integer type arrays.

Is it int [] array or int array []?

They are semantically identical. The int array[] syntax was only added to help C programmers get used to java. int[] array is much preferable, and less confusing. The [] is part of the TYPE, not of the NAME.

What does int [] [] mean in Java?

Since int[] is a class, it can be used to declare variables. For example, int[] list; creates a variable named list of type int[]. This variable is capable of referring to an array of ints, but initially its value is null (if it is a member variable in a class) or undefined (if it is a local variable in a method).

What is int [] called in Java?

int - stores integers (whole numbers), without decimals, such as 123 or -123. float - stores floating point numbers, with decimals, such as 19.99 or -19.99.


1 Answers

Both are equivalent. Take a look at the following:

int[] array;  // is equivalent to  int array[]; 
int var, array[];  // is equivalent to  int var; int[] array; 
int[] array1, array2[];  // is equivalent to  int[] array1; int[][] array2; 
public static int[] getArray() {     // .. }  // is equivalent to  public static int getArray()[] {     // .. } 
like image 69
Eng.Fouad Avatar answered Sep 22 '22 03:09

Eng.Fouad