Sunday, February 22, 2009

sample code to demonstrate LinkedList class



// Linked List simple application

package collection;

import java.util.LinkedList;

public class LinkedListDemo {

public static void main(String[] args)
{
LinkedList l=new LinkedList();

l.add(new Integer(30));

l.add(new Integer(10));
l.add(new Integer(40));
l.add(new Integer(30));

System.out.println(l);

l.addFirst(new Integer(5));
l.addLast(new Integer(50));

System.out.println(l);
}
}

output:
[30, 10, 40, 30]
[5, 30, 10, 40, 30, 50]



0 comments:

Post a Comment