Java LinkedList addFirst Example
LinkedList class addFirst method example. This example shows you how to use addFirst method.
LinkedList class addFirst method example.public void addFirst(LinkedList e)Inserts the specified element at the beginning of this list.
Here is the code
/**
* @ # AddFirst.java
* A class repersenting use to addFirst() method of LinkedList class in java.util package
* version 15 May 2008
* author Rose India
*/
import java.util.*;
public class AddFirst {
public static void main(String args[]) {
LinkedList list = new LinkedList();
String str = "Rose";
//Add the specified element to the end of this list.
list.add(str);
list.add("India");
System.out.println("list " + list);
//Add the specified element to the First of this list.
list.addFirst("356");
System.out.println("list = " + list);
}
} |
Output
list [Rose, India]
list = [356, Rose, India |
|