3:13 pm - Wednesday December 17, 1360

LinkedList to Remove last element on output RemoveLast() method

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044

BACK

ThisĀ  methodĀ  used to remove last element from the LinkedList.

Example Program


package com.example;

import java.util.*;

public class LinkedListRemoveLast {
	public static void main(String[] args) { // create a LinkedList
		LinkedList list = new LinkedList(); // add some elements
		list.add("Welcome");
		list.add("to");
		list.add("Java Class");
		list.add("at 10am"); // print the list
		System.out.println("LinkedList:" + list); // remove the last element
		System.out.println("Last element:" + list.removeLast()); // print the
																	// list
		System.out.println("LinkedList:" + list);
	}
}


output:

LinkedList[Welcome, to, Java Class, at 10am]

Last element:at 10am

LinkedList[Welcome, to, Java Class]

 

Description

The java.util.LinkedList.removeLast() method removes and returns the last element from this list.

Declaration

Following is the declaration for java.util.LinkedList.removeLast() method

public E removeLast()

Parameters

  • NA

Return Value

This method returns the last element from this list

Exception

  • NoSuchElementException — if this list is empty

BACK

Filed in: Java Examples

Comments are closed.