adsense


Showing posts with label JAVA EXAMPLES UPDATING LINKED LIST. Show all posts
Showing posts with label JAVA EXAMPLES UPDATING LINKED LIST. Show all posts

Friday, 30 October 2015

JAVA EXAMPLES UPDATING LINKED LIST PAGE 149

COMPUTER LANGUAGES HTML,C,C++.JAVA,.NET AND MULTIMEDIA basics and programs click home button



JAVA EXAMPLES UPDATING LINKED LIST









Java Examples - Updating Linked List




Problem Description:
How to update a linked list ?
Solution:
Following example demonstrates how to update a linked list 
by using listname.add() and listname.set() methods of 
LinkedList class.
import java.util.LinkedList;

public class MainClass {
   public static void main(String[] a) {
      LinkedList officers = new LinkedList();
      officers.add("B");
      officers.add("B");
      officers.add("T");
      officers.add("H");
      officers.add("P");
      System.out.println(officers);
      officers.set(2, "M");
      System.out.println(officers);
   }
}
Result:
The above code sample will produce the following result.
BBTHP
BBMHP