minus()

优质
小牛编辑
125浏览
2023-12-01

创建一个由原始元素组成的新List,而不包含集合中指定的元素。

语法 (Syntax)

List minus(Collection collection)

参数 (Parameters)

Collection - 列表中减去值的集合。

返回值 (Return Value)

新的值列表。

例子 (Example)

以下是此方法的使用示例 -

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

当我们运行上述程序时,我们将得到以下结果 -

[11, 14]