Set an Element at specified index in LinkedList Example

Set an Element at specified index in LinkedList Example


Posted in : Java Posted on : November 29, 2010 at 5:27 PM Comments : [ 0 ]

This Java Example shows how to Set(replace) an element at the specified index in the specified LinkedList object in java.

Set an Element at specified index in LinkedList Example

This Java Example shows how to Set(replace) an element at the specified index in the specified LinkedList object  in java. To set(replace) the element from LinkedList object we use Object set(int index,E element) method. This method returns the element replaced from the LinkedList.

 Example: SetElementatIndexofLinkedList.java

package devmanuals.com;

import java.util.*;

public class SetElementatIndexofLinkedList {
	public static void main(String[] args) {

		LinkedList LKLST = new LinkedList();
		LKLST.add("1");
		LKLST.add("2");
		LKLST.add("3");
		LKLST.add("4");
		LKLST.add("5");
		System.out.println("The Linked List is as : " + LKLST);
		LKLST.set(2, "Gyan");
		LKLST.set(3, "Singh");
		System.out.println("The Updated Linked List is as : " + LKLST);

	}
}

Output:

The Linked List is as : [1, 2, 3, 4, 5]

 The Updated Linked List is as : [1, 2, Gyan, Singh, 5]

Download The Code

Go to Topic «PreviousHomeNext»

Your Comment:


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

 
Tutorial Topics