2

like the title says, I want to add multiple values to my arrayList in Groovy. But it is not accepted.

Collection<String> actorCollection = new ArrayList<>();
actorCollection.add("first","second");

If there is only a single value, it works perfectly.

Thanks in advance!

1 Answer 1

3

Use addAll: actorCollection.addAll("first","second")

Note: Groovy's list literal will give you an array list. So could just write def actorCollection = [] or even ... = ["first", "second"] to fill the list with the values right from the beginning.

Sign up to request clarification or add additional context in comments.

2 Comments

Interesting. I didn't know groovy offered a var-arg overload for addAll().
@ernest_k yep, and also for an interator

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.