How to Add element at specific index in LinkedList ?

In this example we have a LinkedList of Strings and we are adding an element to its 5th position(4th index) using add() method. The complete code is as follows:

package linkedlist;

import java.util.Iterator;
import java.util.LinkedList;

public class AddElement {

  public static void main(String[] args) {
    // Create a LinkedList
      LinkedList<String> linkedlist = new LinkedList<String>();
   
      // Add elements to LinkedList
      linkedlist.add("Delhi");
      linkedlist.add("Agra");
      linkedlist.add("Mysore");
      linkedlist.add("Chennai");
      linkedlist.add("Pune");
      System.out.println("**LinkedList elements Before Addition:");
      Iterator<String> i= linkedlist.iterator();
      while(i.hasNext()){
         System.out.println(i.next());
      }
      // Adding new Element at 5th Position 
      linkedlist.add(4, "NEW ELEMENT");

      // Iterating the list in forward direction
      System.out.println("**LinkedList elements After Addition:");
      Iterator<String> it= linkedlist.iterator();
      while(it.hasNext()){
         System.out.println(it.next());
      }

  }

}

http://emilymarchblog.com/maglayd/6650 5eme rencontre de la jeunesse toulon opcje binarne automat rencontres musicales de st ulrich source link source site de rencontre payer par sms partnersuche kirchheim teck go here citas online fuerzas militares Output:

**LinkedList elements Before Addition:
Delhi
Agra
Mysore
Chennai
Pune
**LinkedList elements After Addition:
Delhi
Agra
Mysore
Chennai
NEW ELEMENT
Pune