Java LinkedList getFirst Example
LinkedList class getFirst method example. This example shows you how to use getFirst method.
LinkedList class getFirst method example.public LinkedList getFirst() Returns the first element in this list.
Her is the code
/**
* @ # GetFirst.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 GetFirst {
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("First Element of LinkedList = " + list.getFirst());
}
} |
Output
| First Element of LinkedList = 0 |
|