Groovy - 列表 minus()



使用未在集合中指定的項組成原始列表的新列表。

語法

List minus(Collection collection)

引數

集合 – 要在列表中減去的數值集合。

返回值

新數值列表。

示例

以下為使用此方法的示例–

class Example { 
   static void main(String[] args) { 
      def lst = [11, 12, 13, 14]; 
      def newlst = [];
      
      newlst = lst.minus([12,13]); 
      println(newlst); 
   } 
}

執行上述程式後,將獲得以下結果:-

[11, 14]
groovy_lists.htm
廣告
© . All rights reserved.