Java examples for Collection Framework:LinkedList
Get SubList from LinkedList
import java.util.LinkedList; import java.util.List; public class Main { public static void main(String[] args) { //from ww w.j av a 2 s.c o m //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"); System.out.println("LinkedList contains : " + lList); List lst = lList.subList(1,4); System.out.println("Sublist contains : " + lst); //remove element from sublist lst.remove(2); System.out.println("Sublist now contains : " + lst); System.out.println("Original LinkedList now contains : " + lList); } }