搜索字符串我有点新的节目,很抱歉,如果这是愚蠢..队列
我有一个字符串的队列,我想在此代码搜索关于元素“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](http://ideone.com/g4Td0s))。你有什么问题? – dasblinkenlight 2014-12-03 20:34:06
你在使用什么编译器和你在哪个版本的Java?这在Java 7中与Eclipse一起运行良好。 – Drew 2014-12-03 21:07:29