I'm getting an error when trying to create the linked list that says:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The type LinkedList is not generic; it cannot be parameterized with arguments <String>
at LinkedList.main(LinkedList.java:7)
Anyone know how to fix this error? Here is the program:
import java.util.*;
public class LinkedList {
public static void main(String[] args) {
List<String> list = new LinkedList<String>();
Scanner input = new Scanner(System.in);
System.out.print("How many elements do you want to add: ");
int num = input.nextInt();
for(int i = 0; i < num; i++) {
System.out.print("Add Element: ");
String element = input.next();
list.add(element);
}
System.out.println();
System.out.println("LinkedList elements are: ");
for(int i = 0; i < list.size(); i++) {
System.out.println(list.get(i));
}
}
}