Groovy subList()方法

2018-12-29 15:55 更新

返回此指定的fromIndex(包括)和toIndex(排除)之間的此范圍部分的視圖。

句法

List subList(int fromIndex, int toIndex)

參數(shù)

  • fromIndex - 范圍的起始索引
  • toIndex - End范圍的索引

返回值

從指定的開始到結(jié)束索引的范圍值的列表。

下面是一個(gè)使用這個(gè)方法的例子 -

class Example { 
   static void main(String[] args) { 
      def rint = 1..10; 
		
      println(rint.subList(1,4)); 
      println(rint.subList(4,8)); 
   } 
}

當(dāng)我們運(yùn)行上面的程序,我們將得到以下結(jié)果 -

[2, 3, 4] 
[5, 6, 7, 8] 
以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)