提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
从LinkedList中删除元素范围
import java.util.LinkedList; import java.util.List; /* 来 自* n o w j a v a . c o m */ public class Main { public static void main(String[] args) { //create LinkedList object LinkedList lList = new LinkedList(); //add elements to LinkedList lList.add("1"); lList.add("2"); lList.add("3"); lList.add("4"); lList.add("5"); /** from n o w j a v a . c o m**/ System.out.println("LinkedList contains : " + lList); //remove elements from index 2(inclusive) to 5(exclusive) lList.subList(2,5).clear();