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!