0

Does placing the square brackets before int [ ] arr; or after int arr[ ]; have any impact on the time complexity of the program?

18th Apr 2017, 12:12 PM
Taku Remwa
Taku Remwa - avatar
3 Antworten
+ 7
Reason why it's a convention: It's more practical, take a look at the following examples: int ar[], array[], array3[]; or just do int[] ar, array, array3; Method 2 is easier to follow, and less things to write. If I did: int a, arr[] , etc.. This could lead to a mess of confusion, as I'm forced to pay attention to the syntax to find what type the variable could be. Where as: int[] arr; int a; No matter how many variables I have, I only need to look in one place.
18th Apr 2017, 5:23 PM
Rrestoring faith
Rrestoring faith - avatar
+ 2
it will work just the same but as @seamiki said, its convention to do type [ ] variable by convention, and you should always stick to convention
18th Apr 2017, 3:27 PM
Edward
+ 1
by convention, the square brackets go after the data type: it's more intuitive. int[ ] yourArray; but it shouldn't harm your code if you do the other way. there is no direct mention of it in the Java coding conventions but if you go through the java source file example, at point 11, you'll find a reference. http://www.oracle.com/technetwork/java/javase/documentation/codeconvtoc-136057.html Quoting the a.m. example page : http://www.oracle.com/technetwork/java/javase/documentation/codeconventions-137946.html#182 ...private Object[ ] instanceVar3; ...
18th Apr 2017, 12:23 PM
seamiki
seamiki - avatar