Dynamically adding elements to ArrayList in Groovy

前端 未结 2 433
南笙
南笙 2021-02-04 23:46

I am new to Groovy and, despite reading many articles and questions about this, I am still not clear of what is going on. From what I understood so far, when you create a new ar

2条回答
  •  眼角桃花
    2021-02-05 00:26

    The Groovy way to do this is

    def list = []
    list << new MyType(...)
    

    which creates a list and uses the overloaded leftShift operator to append an item

    See the Groovy docs on Lists for lots of examples.

提交回复
热议问题