Java LinkedList element Example
LinkedList class element method example. This example shows you how to use element method.
LinkedList class element method example.public LinkedList element() Retrieves, but does not remove, the head (first element) of this list.
Here is the code
/**
* @ # Element.java
* A class repersenting use to element method of LinkedList class in java.util package
* version 15 May 2008
* author Rose India
*/
import java.util.*;
public class Element {
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("list = " + list);
//First element of the list
System.out.println("First Element "+list.element());
}
} |
Output
list = [0, Rose, India]
First Element 0 |
|