import java.util.LinkedList; public class Main { public static void main(String[] args) { LinkedListlist = new LinkedList (); list.add("Apple"); list.add("Orange"); list.add("Banana"); list.add("Grapes"); System.out.println("Original list: " + list); //Updating the third node with a new value list.set(2, "Kiwi"); System.out.println("Updated list: " + list); } }
import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.control.TreeItem; import javafx.scene.control.TreeView; import javafx.stage.Stage; public class Main extends Application { public void start(Stage primaryStage) { TreeItemIn this code snippet, a new TreeView object is created and two nodes are added to it as children of a root node using the addAll() method. The text of the second node is then updated with a new value ("New Value") using the setValue() method. Finally, the updated tree is displayed in a JavaFX Scene and Stage using the Scene and Stage classes from the JavaFX library.root = new TreeItem<>("Root"); TreeItem node1 = new TreeItem<>("Node1"); TreeItem node2 = new TreeItem<>("Node2"); root.getChildren().addAll(node1, node2); TreeView tree = new TreeView<>(root); //Updating the text of the second node node2.setValue("New Value"); Scene scene = new Scene(tree, 200, 200); primaryStage.setScene(scene); primaryStage.show(); } public static void main(String[] args) { launch(args); } }