如何在java中传递一个整数数组到队列接口



我试图在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[]>"

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

push()不是由Queue接口声明的方法。使用不同的方法或将q声明为LinkedList

使用队列。提供(新int [] {0});

可以了

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

最新更新