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

Java Example - Delete Array Elements

黄舟
Release: 2017-02-18 10:17:54
Original
1227 people have browsed it

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);
   }
Copy after login

The output result of running the above code is:

数组删除元素前:[第 0 个元素, 第 1 个元素, 第 2 个元素]
数组删除元素后:[第 0 个元素, 第 2 个元素]
Copy after login

The above is the Java example - delete array elements For more related content, please pay attention to the PHP Chinese website (www.php.cn)!


Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template