Home > Java > javaTutorial > Java data structure deleting elements in the linked list example code

Java data structure deleting elements in the linked list example code

高洛峰
Release: 2017-01-24 16:22:20
Original
1955 people have browsed it

java Delete elements in a linked list

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

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

Running results:

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

Thank you for reading, I hope it can help everyone, thank you for your support of this site!

For more Java data structure deletion element example code related articles, please pay attention to the PHP Chinese website!

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