flutter 接口队列
In Java, the Queue interface is under java.util package. The queue extends the collection interface. It is used to hold an element in a collection which are to be processed and can also perform operations like insertion, deletion etc. In this interface elements are inserted at the end of the list and deleted from the start of the list. Its follows the concept of FIFO i.e First In First Out. To declare a queue a concrete class is required, mostly PriorityQueue and LinkedList class is used.
在Java中,Queue接口位于java.util包下。 队列扩展了收集接口。 它用于将元素保留在要处理的集合中,还可以执行插入,删除等操作。在此接口中,元素插入列表的末尾,然后从列表的开头删除。 它遵循FIFO的概念,即先进先出 。 要声明队列,需要一个具体的类,主要使用PriorityQueue和LinkedList类。
下面是队列接口的方法。 ( Below is the method of Queue interface. )
S.no. | Method | Description |
---|---|---|
1 | add() | It is used for adding elements in the queue. |
2 | peek() | It used to view the head of the queue.. |
3 | element() | It is used to check whether the queue is empty or not. If empty it throws NoSuchElementFound. |
4 | remove() | It is used to remove the elements from the head of the queue. |
5 | poll() | It is used to remove an element and return the head of the queue. |
6 | size() | It is used to get the size of the element. |
序号 | 方法 | 描述 |
---|---|---|
1个 | 加() | 它用于在队列中添加元素。 |
2 | 窥视() | 它用来查看队列的头。 |
3 | 元件() | 用于检查队列是否为空。 如果为空,则抛出NoSuchElementFound。 |
4 | 去掉() | 它用于从队列的开头删除元素。 |
5 | 轮询() | 它用于删除元素并返回队列的开头。 |
6 | 尺寸() | 它用于获取元素的大小。 |
Example:
例:
import java.util.LinkedList;
import java.util.Queue;
public class QueueDemo1
{
public static void main(String[] args)
{
Queue<Integer> a = new LinkedList<>();
for (int i=0; i<10; i++)
a.add(i);
System.out.println("**************************************");
System.out.println("Elements of Queue : "+a);
System.out.println("**************************************");
int b= a.remove();
System.out.println("Removed element from the Queue : " + b);
System.out.println(a);
System.out.println("**************************************");
int c = a.peek();
System.out.println("head of queue-" + c);
System.out.println("**************************************");
int d= a.size();
System.out.println("Size of queue-" + d);
}
}
![queue-example](https://i-blog.csdnimg.cn/blog_migrate/4632ce5eb9b7eaefc9ec50023518a965.png)
flutter 接口队列