What's wrong with: LinkedList<String> stringList = new LinkedList<String>();
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.
Are you possibly compiling against a JDK 1.4 or earlier? Or do you have your language setting in your build or IDE set to pre-5.0 (so no generics support)?
By the way, the best way to do that is
List<String> stringList = new LinkedList<String>();
Use the interface rather than the implementation wherever possible.
That being said, assuming you're compiling against a JDK 5.0+, have your language settings set to Java 5+ and that is a java.util.LinkedList then your code is perfectly valid.
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.