【问题标题】:How to pass an integer array to queue interface in java如何将整数数组传递给java中的队列接口
【发布时间】:2021-05-29 19:48:29
【问题描述】:

我正在尝试在 java 中创建一个以整数数组作为参数的队列:

Queue<int[]> q=new LinkedList<>();
q.push(new int[]{0,0});

我收到错误:

cannot find symbol
    q.push(new int[]{0,0});
     ^
symbol:   method push(int[])
location: variable q of type Queue<int[]>"

如何将数组传递给这个队列?

【问题讨论】:

  • 请注意qQueue,而不是LinkedList,因为您声明它是Queue,即使您随后实例化 作为LinkedList
  • 是的,现在意识到了!

标签: java arrays collections queue


【解决方案1】:

push() 不是declared by the Queue 接口的方法。使用其他方法或将q 声明为LinkedList

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-01-07
    • 1970-01-01
    • 2020-09-11
    • 2014-10-20
    • 2014-08-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多