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] |

[ 0 ] Comments