Appendix D. Cheat sheets

Cheat sheets provide you with quick information and examples to get you up and running quickly. For more details about any topic, refer to the corresponding section in the book or on the Groovy web site’s wiki.

Lists

See section 4.2.

assert [1,2,3,4] == (1..4) assert [1,2,3] + [1] == [1,2,3,1] assert [1,2,3] << 1 == [1,2,3,1] assert [1,2,3,1] - [1] == [2,3] assert [1,2,3] * 2 == [1,2,3,1,2,3] assert [1,[2,3]].flatten() == [1,2,3] assert [1,2,3].reverse() == [3,2,1] assert [1,2,3].disjoint([4,5,6]) assert [1,2,3].intersect([4,3,1]) == [3,1] assert [1,2,3].collect{ it+3 } == [4,5,6] assert [1,2,3,1].unique().size() == 3 assert [1,2,3,1].count(1) == 2 assert [1,2,3,4].min() == 1 assert [1,2,3,4].max() == 4 assert [1,2,3,4].sum() ...

Get Groovy in Action now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.