Groovy - subList()
返回此 Range 在指定 fromIndex(包括)和 toIndex(不包括)之间部分的视图
语法
List subList(int fromIndex, int toIndex)
参数
- fromIndex – 范围的起始索引
- toIndex – 范围的结束索引
返回值
从指定起始索引到结束索引的范围值列表。
以下是该方法的用法示例 −
class Example {
static void main(String[] args) {
def rint = 1..10;
println(rint.subList(1,4));
println(rint.subList(4,8));
}
}
当我们运行上面的程序时,会得到下面的结果 −
[2, 3, 4] [5, 6, 7, 8]

