Tuesday, 30 May 2017

Remove element from linked list

package javaRadarLinkedList;

import java.util.LinkedList;

public class RemoveAtIndex {

      public static void main(String[] args) {
            //create Array List
            LinkedList<String> javaRadarList = new LinkedList<String>();
            //Add elements to ArrayList
            javaRadarList.add("Java");
            javaRadarList.add("Jquery");
            javaRadarList.add("Spring");
            javaRadarList.add("Hibernate");
            javaRadarList.add("EJB");
           
            System.out.println("Before Removal");
            for(String list : javaRadarList){
                  System.out.println(list);
            }
           
            //Remove element from 2nd position
            javaRadarList.remove(1);
           
            System.out.println("After Removal");
            for(String list : javaRadarList){
                  System.out.println(list);
            }

      }

}


OUTPUT:

Before Removal
Java
Jquery
Spring
Hibernate
EJB
After Removal
Java
Spring
Hibernate
EJB

No comments:

Post a Comment

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
If you are looking for a reference book on java then we recommend you to go for → Java The Complete Reference
Click on the image link below to get it now.