grails groovy list getAt(start..end)with Variables

时间:2014-10-23 10:19:19

标签: list groovy range

如何通过变量获取监听:

var start = 5
var end = 10
myList.getAt(start..end)

1 个答案:

答案 0 :(得分:2)

你走了:

def list = [1,2,4]
def a = 1
def b = 2
assert list.getAt((a)..(b)) == [2, 4]
assert list[a..b] == [2, 4]