def foo = [] def myList = ["Apple", "Banana", "Orange"] println myList.class // class java.util.ArrayList
def first = ["a", "b", "c"] def second = ["d", "e", "f"] assert ["a", "b", "c", "d", "e", "f"] == (first + second)
// pop
def list = ["a", false, 2]
assert list.pop() == ‘a‘
assert list == [false, 2]
// push
def list = [3, 4, 2]
list.push("x")
assert list == [‘x‘, 3, 4, 2]
list.add(0, element)
import static groovy.json.JsonOutput.* def config = [‘test‘: ‘lalala‘] println prettyPrint(toJson(config))
def lst = [1,2,3,4];
def newlst = lst.collect {element -> return element * element}
println(newlst);
如果 Closure 没有返回,则会存在 null 元素。使用 newlst.findAll { it != null } 过滤。
「Groovy」- 常用字符串操作(String)
 「Groovy」- 常用 MAP 操作
 Java ArrayList insert element at beginning example
 Combine two lists
 A simple way to pretty print nested lists and maps in Groovy.
 Groovy List Tutorial And Examples
 List (Groovy JDK enhancements)
 Groovy - collect() - Tutorialspoint
 groovy - Remove null and empty values using collect with string array - Stack Overflow
 Remove null items from a list in Groovy - Stack Overflow 
「Groovy」- 常用列表操作(List) @20210307
原文:https://www.cnblogs.com/k4nz/p/14493714.html