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] |
[ 0 ] Comments