How to Get a Sublist of LinkedList in Java


The example will demonstrate how to get a sublist from LinkedList in Java.

Source Code

package com.beginner.examples;

import java.util.LinkedList;
import java.util.List;

public class GetSubListOfLinkedListExample {

	
	public static void main(String[] args) {
		
		LinkedList ll= new LinkedList();
		
		ll.add("a");
		ll.add("b");
		ll.add("c");
		ll.add("d");
		
		List subList = ll.subList(1, 3);
		
		System.out.println("SubList:"+subList);
	}

}

Output:

SubList:[b, c]

References

Imported packages in Java documentation:

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments