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

Java Example - Delete Array Elements

黄舟
Release: 2017-02-18 10:17:54
Original
1254 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:
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
Latest Issues
Install JAVA
From 1970-01-01 08:00:00
0
0
0
Unable to install java
From 1970-01-01 08:00:00
0
0
0
Can java be used as the backend of the web?
From 1970-01-01 08:00:00
0
0
0
Is this in Java language?
From 1970-01-01 08:00:00
0
0
0
Help: JAVA encrypted data PHP decryption
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template