Java examples for Collection Framework:LinkedList
You can use the set method to replace an object in a linked list with another object.
import java.util.LinkedList; public class Main { public static void main(String[] args) { LinkedList<String> officers = new LinkedList<String>(); // add the original officers officers.add("Blake"); officers.add("Burns"); officers.add("Tuttle"); officers.add("book2s"); officers.add("Pierce"); officers.add("java2s.com"); System.out.println(officers); officers.set(2, "new"); System.out.println("\nTuttle is replaced:"); System.out.println(officers); }/*from w w w. java2 s . c o m*/ }