Free Data Structures and Algorithms Course









Subscribe below and get all best seller courses for free !!!










OR



Subscribe to all free courses

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 :


 
© 2021 Learn Java by Examples Template by Hubberspot