I am trying to add a string to an ArrayList in Java, but I can’t seem to get it to work.
Currently, I have the following code:
List food_names = new ArrayList();
food_names.add("pizza");
Why do I get these errors:
- Syntax error on token “”pizza””, delete this token
- Syntax error on token(s), misplaced construct(s)
You have to use
food_names.add("pizza")in function, for example:Hope helps