Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's wrong with: LinkedList<String> stringList = new LinkedList<String>();

Tags:

java

When I try:

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

I get the following compilation error:

type LinkedList does not take parameters

What am I missing? Can't you do this?

like image 748
Eric Wilson Avatar asked Aug 02 '09 00:08

Eric Wilson


2 Answers

Don't take the class name as class LinkedList instead you can take class LinkedListDemo and rest of the declaration LinkedList<String> t = new LinkedList<String>(); should be there and it will compile perfectly.

like image 114
saheer Avatar answered Oct 10 '22 16:10

saheer


Check to make sure you don't have a compiled class named LinkedList in the same directory. (Especially since "linked list" is a common term, and it is something that people often try to implement as beginners.) This is important if you import your classes using something like import java.util.*;, because the * imports on-demand, so if there is a class with the same name in the package already, then that class is used and the java.util.LinkedList is not imported.

like image 38
newacct Avatar answered Oct 10 '22 17:10

newacct