返回此 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]
相關用法
- Groovy subString()用法及代碼示例
- Groovy sin()用法及代碼示例
- Groovy split()用法及代碼示例
- Groovy setTime()用法及代碼示例
- Groovy sqrt()用法及代碼示例
- Groovy matches()用法及代碼示例
- Groovy after()用法及代碼示例
- Groovy padRight()用法及代碼示例
- Groovy contains()用法及代碼示例
- Groovy exp()用法及代碼示例
- Groovy equals()用法及代碼示例
- Groovy before()用法及代碼示例
- Groovy pow()用法及代碼示例
注:本文由純淨天空篩選整理自 Groovy - subList()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。