'(' or '[' Expected

When trying to compile my program, the following error occurs.

'(' or '[' Expected.

 public AccountArrayList()
{
    // line one below is the hi-lighted code
    ArrayList accounts = new ArrayList;
    accounts.add("1");
    accounts.add("1");
    accounts.add("1");
    accounts.add("1");
    accounts.add("1");
    accounts.add("1");
    accounts.add("1");
    accounts.add("1");
    accounts.add(5,"900");
}

Thank.

+5
source share
5 answers

There is no bracket in the constructor:

ArrayList accounts = new ArrayList();
+12
source

Your constructor is wrong. It should be:

ArrayList accounts = new ArrayList();
+4
source

Java 5 , , ArrayList generics.

:

ArrayList<String> accounts = new ArrayList<String>();
+2

, ArrayList, .

new ArrayList()

0

,

ArrayList accounts = new ArrayList();

In addition, it would be useful for you to specify it like this:

ArrayList<String> accounts = new ArrayList<String>();

Because then the compiler will stop you from adding integers to it (for example), not strings.

0
source

All Articles