Home  >  Article  >  Java  >  Java Example - Delete Array Elements

Java Example - Delete Array Elements

黄舟
黄舟Original
2017-02-18 10:17:541192browse

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)!


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn