[Solved] When I try to add Strings to an Array List I get an “illegal start of type error”


To add items to a static list you can use the block static{}

public class Employee {
....

 private static ArrayList <String> employeeID = new ArrayList <String> ();
 static {
  employeeID.add("632584");
  employeeID.add("259415");
  employeeID.add("257412");
  employeeID.add("953647");
  employeeID.add("126497");
  employeeID.add("453256");
  employeeID.add("125689");
 }

...
 }
}

Or use constructor

public class Employee {
....

 private static ArrayList <String> employeeID = new ArrayList <String> ()
 {{
  add("632584");
  add("259415");
  add("257412");
  add("953647");
  add("126497");
  add("453256");
  add("125689");
 }};

...
 }
}

solved When I try to add Strings to an Array List I get an “illegal start of type error”