The following example demonstrates how to use the remove () method to delete array elements:
/* author by w3cschool.cc 文件名:Main.java */import java.util.ArrayList;public class Main { public static void main(String[] args) { ArrayList objArray = new ArrayList(); objArray.clear(); objArray.add(0,"第 0 个元素"); objArray.add(1,"第 1 个元素"); objArray.add(2,"第 2 个元素"); System.out.println("数组删除元素前:"+objArray); objArray.remove(1); objArray.remove("0th element"); System.out.println("数组删除元素后:"+objArray); }
The output result of running the above code is:
数组删除元素前:[第 0 个元素, 第 1 个元素, 第 2 个元素] 数组删除元素后:[第 0 个元素, 第 2 个元素]
The above is the Java example - delete array elements For more related content, please pay attention to the PHP Chinese website (www.php.cn)!