![](/img/trans.png)
[英]CircularFifoQueue doesn't work inside the method, what to use instead?
[英]CircularFIFOQueue : Using get method
我正在嘗試在Java中實現CircularFifoQueue。
Queue<List<String>> rssififo = new CircularFifoQueue<List<String>>(2);
我對如何使用CircularFifoQueue API的get方法感到困惑。 API狀態
public E get(int index)
Returns the element at the specified position in this queue.
Parameters:
index - the position of the element in the queue
Returns:
the element at position index
Throws:
NoSuchElementException - if the requested position is outside the range [0, size)
但是我似乎無法使用rssiinfo.get(index)
。 如果我使用rssiinfo.element().get(0)
,則在我的編輯器(android studio)中彈出get方法的唯一方法。
但是element()方法僅返回隊列的第一個元素。 如何訪問隊列中任意位置的元素?
您的變量rssififo
是通用的Queue
類型,而不是具體的類型CircularFifoQueue
。
Queue接口沒有get方法,只有peek,poll和remove方法。 如果將聲明更改為CircularFifoQueue
則可以訪問get方法。
您必須將代碼更改為
CircularFifoQueue<List<String>> rssififo = new CircularFifoQueue<List<String>>(2);
CircularFifoQueue具有方法get(int index)。 但是CircularFifoQueue實現了Queue接口。 接口沒有方法get(int index)。 這就是您無法使用此功能的原因。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.