Pin It

How to use LinkedList in Java with example ?.

Program to demonstrate how to implement LinkedList class in java.util.*; package along with its operations :

package com.hubberspot.collections.example;

import java.util.*;

public class LinkedListExample
{
  public static void main(String[] args)
  {
    LinkedList list=new LinkedList();
    list.add("a");
    list.add("b");
    list.add(new Integer(5));
  
    System.out.println("The contents of array is " + list);
    System.out.println("The size of linkedlist is "
       +list.size());
    
    list.addFirst(new Integer(10));
    System.out.println("The contents of array is " + list);

    list.addLast("c");
    list.add(2,"d");
    list.add(1,"e");
    list.remove(3);
    
    System.out.println("The contents of array is " + list);  
    System.out.println("The size of linkedlist is "
       + list.size());
 } 
}

Output of the program :


Please Give Us Your 1 Minute In Sharing This Post!
SOCIALIZE IT →
FOLLOW US →
SHARE IT →
Related Posts Plugin for WordPress, Blogger...

Post your related queries below ...

comments powered by Disqus
Powered by Blogger.
 
© 2012 Learn Java by Examples Template by Hubber Spot