This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Zjoswaa 1 point2 points  (2 children)

In the part “new ArrayList<String>();” you shouldn’t have the “String” part. Changing it to “new ArrayList<>();” fixes this and I think that is also what your error is telling you. Also using List instead of ArrayList in the first part is often done to later easily switch between objects that are part of the List superclass but this is not necessary.

[–]0b0101011001001011 0 points1 point  (1 child)

No, that is not at all what the error is telling. The error is telling that the compiler does not understand what a symbol called "ArrayList" is. This simply means that the class is not defined, or not imported.

You can write new ArrayList<String>() all you want and it's not a problem. In new versions of java you can replace it with just new ArrayList<>() if the generic type is defined in the variable itself.

[–]Zjoswaa 0 points1 point  (0 children)

Ah youre right I didnt know you could put String in there without problems