Java program to add elements using add()

Configurare noua (How To)

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]

Tip solutie

Permanent

Voteaza

(9 din 17 persoane apreciaza acest articol)

Despre Autor

Leave A Comment?