Home > Java > javaTutorial > Java Example - Delete elements from linked list

Java Example - Delete elements from linked list

黄舟
Release: 2017-01-22 16:18:42
Original
1534 people have browsed it

The following example demonstrates the use of the Clear() method to delete elements in a linked list:

/*
 author by w3cschool.cc
 Main.java
 */import java.util.*;public class Main {
   public static void main(String[] args) {
      LinkedList<String> lList = new LinkedList<String>();
      lList.add("1");
      lList.add("8");
      lList.add("6");
      lList.add("4");
      lList.add("5");
      System.out.println(lList);
      lList.subList(2, 4).clear();
      System.out.println(lList);
   }}
Copy after login

The output result of running the above code is:

[1, 8, 6, 4, 5][1, 8, 5]
Copy after login

The above is a Java example - deleting the contents of an element in a linked list. For more information, please visit Follow 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