0

I tied the following, it seems that there's no difference

import java.math.BigInteger;
import java.util.Random;
import java.util.Scanner;


public class Main {

    /**
     * @param args
     */

    final static int MAXN = 100005;



    public static void main(String[] args) {
        // TODO Auto-generated method stub
        int n = 100;
        BigInteger[] a = new BigInteger[n];
        BigInteger b[] = new BigInteger[n];
        for (int i = 0;i < n;i++){
            a[i] = BigInteger.valueOf(i);
        }
        b = a;
        for (int i = 0;i < n;i++){
            b[i] = BigInteger.ZERO;
        }
        if (a == b){
            for (int i = 0;i < n;i++){
                System.out.println(a[i]);
            }
        }
    }

}
iloahz
  • 4,491
  • 8
  • 23
  • 31
  • 3
    The difference, nothing really. They are just different forms of the same thing. Myself I prefer `type[] a` since it is clearer to me, but what matters the most is what is clearer to your boss/instructor/co-workers. – Hovercraft Full Of Eels Apr 13 '13 at 02:28
  • 1
    Hovercraft said it all. Just make sure you don't accidentally make it `type[] a[]` as that will make it a two-dimensional array! – ddmps Apr 13 '13 at 02:30

2 Answers2

1

Its for declaration only... Ex: type a[], b here only a is array, when your declare like type[] a,b both are arrays... Similarly for all types... type[] a,b[] here b is two dimension array...

Kanagaraj M
  • 956
  • 8
  • 18
0

As @Hovercraft Full Of Eels mentioned, they're both equivalent.

T a[] and T[] a are the same.

Java derives its syntax from C which uses the T a[] notation. It's however more "correct" to use T[] a which doesn't split the type information. This is specially noticeable when using a language with type inference (Scala, C# and probably Java 8). In that case, you'd use something like

var a = <some expression which returns a T[]>
Bernard
  • 16,149
  • 12
  • 63
  • 66