import java.util.LinkedList; public class LinkedListExample { public static void main(String[] args) { LinkedListlist = new LinkedList (); // add elements to the list list.add("Apple"); list.add("Banana"); list.add("Cherry"); // add a new node to the end of the list list.add("Date"); System.out.println(list); } }
import org.apache.commons.graph.*; import org.apache.commons.graph.builder.*; public class GraphExample { public static void main(String[] args) { MutableGraphgraph = GraphBuilder.undirected().build(); // add nodes to the graph graph.addVertex("A"); graph.addVertex("B"); graph.addVertex("C"); // add a new node to the graph graph.addVertex("D"); System.out.println(graph); } }
{ A=[B], B=[A, C], C=[B], D=[] }In summary, adding nodes to data structures is a common operation in programming, and there are various libraries and packages available in Java for implementing this. The specific package or library used will depend on the type of data structure being used and the requirements of the project.