LinkedList E getLast()method Example Program


Returns the last element in this list.

Program

package com.candidjava;

import java.util.LinkedList;

/**
 * 
 * @author : mohan
 * @description :The java.util.LinkedList.getLast() method returns the last
 *              element in this list.
 */
public class LinkedListGetLast {
	public static void main(String[] args) {
		LinkedList list = new LinkedList();
		list.add("anandh");
		list.add("hari");
		list.add("vinoth");
		list.add("mohan");
		System.out.println("LinkedList:" + list);
		System.out.println("Last Element :" + list.getLast());
	}
}

Output

LinkedList:[anandh, hari, vinoth, mohan]
Last Element :mohan

Explanation

public E getLast()
Returns the last element in this list.
Specified by:
getLast in interface Deque<E>
Returns:
the last element in this list
Throws:
NoSuchElementException - if this list is empty


Related Post

Comments


©candidjava.com