Tuesday 18 March 2014

Java Program for LinkedList Demonstration

// wap to insert element and delete element and set another
//element to another position

import java.util.*;
class LinkedListDemo
{
    public static void main(String args[])
    {
        LinkedList l1=new LinkedList();
       
        l1.add(11);
        l1.add("A");
        l1.add("B");
        l1.add("C");
        l1.add("D");
        l1.add("E");
        l1.addLast("z");
        l1.addFirst("A1");
        l1.add(1,"A2");
       
        System.out.println("original content of l1:"+l1);
       
        l1.remove("E");
        l1.remove(2);
           
        System.out.println("content of l1 after deletion :"+l1);
       
        l1.removeFirst();
        l1.removeLast();
       
        //Object val=l1.get(2);
        l1.set(2,"W");
        System.out.println("l1 after change:"+l1);
    }
}


No comments: