How to add the elements to the Linked list example
Previous | Home | Next |
This will shows how to add elements the LinkedList.
We use the public boolean add(E e)This will Appends the specified element to the end of this list.
This method will Appends the specified element to the end of this list.
Create the object of the LinkedList as Lst and will add the elements to the list using add()
as Lst.add("@")
package Example;
import java .util.LinkedList;
import java .util.Iterator;
public class LinklistExample {
/**
* @param args
*/
public static void main(String[] args) {
LinkedList Lst= new LinkedList(); // create object of LinkedList
// add elements to the LinkedList using add method
Lst.add("4");
Lst.add("6");
Lst.add("8");
Lst.add("10");
Lst.add("12");
Lst.add("14");
Lst.add("16");
Lst.add("18");
System.out.println("The elements of LinkedList prior to addition of other elemnts are:"+Lst);
The elements of LinkedList prior to addition of other elemnts are:[4, 6, 8, 10, 12, 14, 16, 18]
Previous | Home | Next |