Java LinkedList getLast Example
LinkedList class getLast method example. This example shows you how to use getLast method.
LinkedList class getLast method example.public LinkedList getLast() Returns the last element in this list.
Here is the code
/**
* @ # Getlast.java
* A class repersenting use to getLast method of LinkedList class in java.util package
* version 15 May 2008
* author Rose India
*/
import java.util.*;
public class Getlast {
public static void main(String args[]) {
LinkedList list = new LinkedList();
int i = 0;
String str = "Rose";
//Add the specified element to the end of this list.
list.add(i);
list.add(str);
list.add("India");
System.out.println("Last Element of LinkedList = " + list.getLast());
}
} |
Output
| Last Element of LinkedList = India |
|