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

高洛峰
高洛峰Original
2017-01-24 16:22:201976browse

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);
  }
}

Running results:

[1, 8, 6, 4, 5]
[1, 8, 5]

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!

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