Core Java Tutorial

Core Java Tutorial

LinkedList Example Program for getLast()

[java]
/**
Author :candidjava.com
Description: Returns the Last element in the list.
*/
import java.io.IOException;
import java.util.*;
public class LinkedListGetLast
{
public static void main(String args[])
{
int b=60,c=20,d=30;
LinkedList l=new LinkedList();
l.add(b);
l.add(c);
l.add(d);
System.out.println("Last element in the list is");
System.out.println(l.getLast());
}
}
[/java]

Output:
Last element in the list is
30