Remove Element from First and Last Position Of Java LinkedList

Remove Element from First and Last Position Of Java LinkedList


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

This Java Example shows how to Remove an element of first and last position in java LinkedList object.

Remove Element from First and Last Position Of Java LinkedList Example

This Java Example shows how to Remove an element of first and last  position in java LinkedList object. To remove  an element at first and last position of LinkedList We use Element removeFirst() And removeLast() method. These method removes and returns the first and last element from the LinkedList respectively. 

 Example: RemoveFirstLastElementLinkedList.java

package devmanuals.com;

import java.util.*;

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

		LinkedList LKLST = new LinkedList();
		LKLST.add("Gyan");
		LKLST.add("Singh");
		LKLST.add("Arunesh");
		LKLST.add("Kumar");
		System.out.println("The LinkedList Elements are : " + LKLST);
		LKLST.removeFirst();
		LKLST.removeLast();
		System.out.println("The LinkedList Elements after removal : " + LKLST);

	}
}

Output:

The LinkedList Elements are : [Gyan, Singh, Arunesh, Kumar] 

The LinkedList Elements after removal : [Singh, Arunesh]

Download The Code

Go to Topic «PreviousHomeNext»

Your Comment:


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

 
Tutorial Topics