How to create LinkedList in Java

import java.util.LinkedList;

public class CreateLinkList {

public static void main(String[] args) {

LinkedList<String> linkedList = new LinkedList<String>();

linkedList.add(“Mumbai”);
linkedList.add(“Delhi”);
linkedList.add(“Noida”);
linkedList.add(“Gao”);
linkedList.add(“Patna”);

System.out.println(“Linklist is”+linkedList);

}

}

Output:

Linklist is = [Mumbai, Delhi, Noida, Gao, Patna]

Leave a Reply

Your email address will not be published. Required fields are marked *

5 + = 11