Почему мой LinkedList не будет правильно импортироваться в Eclipse?JAVA

Программисты JAVA общаются здесь
Ответить
Anonymous
 Почему мой LinkedList не будет правильно импортироваться в Eclipse?

Сообщение Anonymous »

Я учусь использовать LinkedList в Java и не могу заставить работать импорт. Я постоянно получаю следующую ошибку:

Код: Выделить всё

Exception in thread "main" java.lang.Error: Unresolved compilation problems:
LinkedList cannot be resolved to a type
LinkedList cannot be resolved to a type
LinkedList cannot be resolved to a type

at StacksQLLExample.main(StacksQLLExample.java:23)
Мой код:

Код: Выделить всё

import java.util.ListIterator;
import java.util.Queue;
import java.util.Stack;
import java.util.LinkedList;

public class StacksQLLExample
{
public static void main(String[] args)
{
Stack s = new Stack();
s.push(1);
s.push(5);
s.push(52);
s.push(Integer.MAX_VALUE);
System.out.println(s);
while (!s.isEmpty())
{
System.out.println("peek: "+ s.peek());
//System.out.println(s);
System.out.println("pop: "+ s.pop());
}

Queue q = new LinkedList();
q.add(1);
q.add(5);
q.add(52);
q.add(Integer.MAX_VALUE);
System.out.println(q);
while (!s.isEmpty())
{
System.out.println("peek: "+ q.peek());
System.out.println("delete: "+ q.remove()) ;
}
System.out.println();

LinkedList ll = new LinkedList();
ll.addFirst("D");
ll.addLast("H");
ll.add("R"); // same as addLast
ll.addLast("T");

System.out.println(ll);
ListIterator iter = ll.listIterator(); // puts iter at the beginning of the list
while (iter.hasNext())
{
String str = iter.next(); // returns what is to the left of the iter
str += str;
System.out.println(str);
}
if (iter.hasNext()) iter.next(); // iter is at the end of the list
iter = ll.listIterator(); // back to the beginning

while (iter.hasNext())
{
String str = iter.next();

if (str.equals("D"))
{
iter.add("J");
}

}
System.out.println(ll);
iter.remove();
System.out.println(ll);
iter.add("K");
System.out.println(ll);
// This creates an error because the iter never moved over with the other element
// You also can't remove what you just added
// iter.remove();
// System.out.println(iter); // prints a memory reference
}
}
Я переключился на IntelliJ IDEA IDE, и там она работает, но в Eclipse, похоже, ничего не работает.

Подробнее здесь: https://stackoverflow.com/questions/783 ... in-eclipse
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «JAVA»