> For the complete documentation index, see [llms.txt](https://notes.eliasnorrby.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://notes.eliasnorrby.com/groovy/add-item-to-list.md).

# Appending items to a list

There are multiple ways of adding items to a list in groovy. One of them is using the `<<` operator:

```groovy
def list = []
list << "item"
```

Another is using `+` or `+=`:

```groovy
list += "a" + ["b", "c", "d"]
```

`<<` is mutating while `+=` is not - it creates a new list.

[Source](http://docs.groovy-lang.org/next/html/documentation/working-with-collections.html#_adding_or_removing_elements)
