Situatie
In this example, we will learn to insert elements to the Java LinkedList using add()
Solutie
Pasi de urmat
import java.util.LinkedList;
class Main {
public static void main(String[] args){
// create a linkedlist
LinkedList<String> tests = new LinkedList<>();
// Add elements to LinkedList
tests.add(“test1”);
tests.add(“test2”);
tests.add(“test3”);
System.out.println(“LinkedList: ” + tests);
}
}
Output:
LinkedList: [test1, test2, test3]
Leave A Comment?