remove()

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

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

语法 (Syntax)

Object remove(int index)

参数 (Parameters)

Index - 需要删除值的索引。

返回值 (Return Value)

删除的值。

例子 (Example)

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

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

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

13 
[11, 12, 14]