Tuesday, November 26, 2013

Published 11/26/2013 by with 0 comment

Dimensions expected after this token / '[' expected

Java error "Dimensions expected after this token" or " '[' expected " can occur while creating array elements or allocating memory using the keyword new. If the square brackets [] are not used properly, you can get this error message.

See the code below:

int myArray[]=new int{10,20,30,40};

Here this is a syntax error. You have to put square brackets [] after new int. To initialize an array the correct code would be:

int myArray[]=new int[]{10,20,30,40};

or just

int myArray[]={10,20,30,40};
    email this       edit

0 comments:

Post a Comment