Related Examples
 

Java LinkedList add Example

LinkedList class add method example. This example shows you how to use add method.


LinkedList class add method example.ublic void add(int index, LinkedList element) Inserts the specified element at the specified position in this list. Shifts the element currently at that position and any subsequent elements to the right.

Here is the code

/**
 * @ # Add1.java
 * A class repersenting use to add(int index,E element) 
 * method of LinkedList class in java.util package
 * version 15 May 2008
 * author Rose India 
 */
import java.util.*;

public class Add1 {

    public static void main(String args[]) {
        List list = new LinkedList();
        int i = 1;
        String str = "Rose India";

        //Add the specified element to the end of this list.
        list.add(i);
        list.add(str);
        System.out.println("arrlist = " + list);
        
        //Add specified element at the specified position in this list.
         list.add(1,11);
         System.out.println("arrlist = " + list);
    }
}

Output
arrlist = [1, Rose India]
arrlist = [1, 11, Rose India]

Post Comment
Name:
E-mail:
Contact no :
Comments:
  Refresh Image
Verify Image:
 
 
Your Comment's
 
 
 

HOME | COPYRIGHT | CONTACT US