Get SubList from Java LinkedList Example

Get SubList from Java LinkedList Example


Posted in : Java Posted on : November 29, 2010 at 5:30 PM Comments : [ 0 ]

This Java Example shows how to get the Sub list of elements from the specified LinkedList object i.e sub list of LinkedList object in java.

Get SubList from Java LinkedList Example

This Java Example shows how to get the Sub list of elements from the specified LinkedList object i.e sub list of LinkedList object in java. To get sub list of the LinkedList object we use List subList(int startIndex,int endIndex) method. This method returns List type sub list of the LinkedList object.

 Example: GetSublistOfLinkedList.java

package devmanuals.com;

import java.util.*;

public class GetSublistOfLinkedList {
	public static void main(String[] args) {

		LinkedList LKLST = new LinkedList();
		LKLST.add("1");
		LKLST.add("2");
		LKLST.add("3");
		LKLST.add("4");
		LKLST.add("5");
		LKLST.add("6");
		System.out.println("The Linked List is as : " + LKLST);
		List SubList = LKLST.subList(2, 5);
		System.out.println("The SubList is as : " + SubList);

	}
}

Output:

The Linked List is as : [1, 2, 3, 4, 5, 6] 

The SubList is as : [3, 4, 5]

Download The Code

Go to Topic «PreviousHomeNext»

Your Comment:


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

 
Tutorial Topics