plus()

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

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

语法 (Syntax)

List plus(Collection collection)

参数 (Parameters)

Collection - 要添加到列表中的值的集合。

返回值 (Return Value)

新的值列表。

例子 (Example)

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

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

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

[11, 12, 13, 14, 15, 16]