使用List操作符
def myList = ['a', 'b', 'c', 'd', 'e', 'f'] //getAt(ranges) assert myList[0..2] == ['a', 'b', 'c'] //getAt(collection of index) assert myList[1, 3, 5] == ['b', 'd', 'f'] //putAt(ranges) myList[0..2] = ['x', 'y', 'z'] assert myList == ['x', 'y', 'z', 'd', 'e', 'f' ] //removing elements myList[0..2] = [] assert myList == ['d', 'e', 'f' ] //adding elements myList[1..1] = ['x', 'y'] assert myList == ['d', 'x', 'y', 'e', 'f']