【发布时间】:2014-12-03 20:29:02
【问题描述】:
我对编程有点陌生,如果这是愚蠢的,请见谅..
我有一个字符串队列,我想要在此代码中搜索关于元素“E”的代码。 因为每次出现这个错误:
字符串不能转换为字符。
public class Queue<Character> {
private java.util.LinkedList<Character> list = new java.util.LinkedList<Character>();
public Queue() {
}
public void clear() {
list.clear();
}
public boolean isEmpty() {
return list.isEmpty();
}
public Character firstEl() {
return list.getFirst();
}
public Character dequeue() {
return list.removeFirst();
}
public void enqueue(Character el) {
list.addLast(el);
}
public String toString() {
return list.toString();
}
public static void main(String []arg) {
Queue<String> student = new Queue<String>();
student.enqueue("A");
student.enqueue("B");
student.enqueue("C");
student.enqueue("D");
student.enqueue("E");
student.enqueue("F");
System.out.println(student.toString());
String mStr = student.dequeue();
System.out.println(mStr + " came first and being served first");
}
}
【问题讨论】:
-
这在 ideone (demo) 上运行良好。你在哪一行有问题?
-
您使用的是什么编译器,您使用的是什么版本的 Java?这对我来说在 Java 7 中运行良好