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); }}
The output result of running the above code is:
[1, 8, 6, 4, 5][1, 8, 5]
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)!