codecamp

Groovy remove()方法

删除此列表中指定位置的元素。

句法

Object remove(int index)

参数

索引 - 需要删除值的索引。

返回值

已移除的值。

例子

下面是一个使用这个方法的例子 -

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

      println(lst.remove(2));
      println(lst);
   }
}

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

13 
[11, 12, 14]
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定