user1464139
user1464139

Reputation:

How many ways are there to declare a two dimensional array in Java?

I have the following as two ways to declare a two dimensional String array. I am being asked to find another way but I don't think there is any other way. Can someone please give me some advice.

    String[][] a = new String[20][20]
    String a[][] = new String[20][20]

Thanks

Upvotes: 0

Views: 568

Answers (1)

siegi
siegi

Reputation: 5996

String[] a[] = new String[20][20]

Edit: Note that this works with methods too:

private String[] a()[]
{
    return new String[20][20];
}

Also note that I do not recommend this notation as it is unclear and confusing!

Upvotes: 6

Related Questions