Java ArrayBlockingQueue 类2025 年 1 月 7 日 | 阅读 3 分钟 ArrayBlockingQueue 是一个有界阻塞队列,它以 FIFO(先进先出)的顺序对元素进行排序。在此队列中,新元素被插入到队列的尾部,元素从队列的头部检索。 ArrayBlockingQueue 类实现了 Collection 和 Iterator 接口的所有可选方法,并且是 Java Collections Framework 的成员。 ArrayBlockingQueue 方法
示例 1输出 Elements : Reema Rahul Rita Ramesh Gita Geetanjali queue.contains(reema) will return true 示例 2输出 Size of the queue : 10 Queue = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] Remaining capacity : 40 Even number = [1, 3, 5, 7, 9] Remaining capacity : 45 Head of the element : 1 Head of the element : 3 Queue : [3, 5, 7, 9] |
Java ArrayBlockingQueue 类的 take() 方法检索并移除 ArrayBlockingQueue 的第一个元素,如果需要,则等待直到有可用元素。语法:public E take() throws InterrupedException 参数:NA 指定者:ArrayBlockingQueue 类 take() 方法由 BlockingQueue<E> 接口中的 take() 方法指定。返回值:take() 方法返回...
阅读 3 分钟
ArrayBlockingQueue() 的 add() 方法在队列容量允许的情况下,将定义的元素附加到队列的末尾。如果成功插入,该方法返回 true,如果队列没有足够的容量,则抛出 IllegalStateException。语法:public boolean add(E e) 参数:e - 这是要添加的元素...
阅读 4 分钟
ArrayBlockingQueue 的 put() 方法将定义的元素添加到此队列的尾部。如果队列已满,它会等到有可用空间才添加。语法:public void put(E e) throws InterruptedException 参数:e - 这是要添加的元素。指定者:ArrayBlockingQueue 类 put() 方法...
阅读 3 分钟
Java ArrayBlockingQueue 类的 removeAll() 方法移除 ArrayBlockingQueue 中包含在指定集合中的元素。语法:public boolean removeAll(Collection<?> c) 参数:这里,参数 c 是包含要从 ArrayBlockingQueue 中移除的元素的集合。指定者:ArrayBlockingQueue 的 removeAll() 方法...
阅读 4 分钟
Java ArrayBlockingQueue 类的 peek() 方法检索此队列的头部,但不会移除它。如果此队列为空,则该方法返回 null。语法:public E peek() 参数:NA 指定者:ArrayBlockingQueue 类 peek() 方法由 Queue 接口中的 peek() 方法指定。返回值:peek() 方法...
阅读 3 分钟
ArrayBlockingQueue 类的 remove() 方法会从队列中移除指定的元素(如果该元素存在于队列中)。语法:public boolean remove(Object o) 参数:传递的参数 'o' 是要从队列中移除的元素(如果存在)。指定者:ArrayBlockingQueue 的 remove() 方法...
阅读 3 分钟
Java ArrayBlockingQueue() 类的 contains() 方法如果指定的元素存在于此队列中,则返回 true。语法:public boolean contains(Object o) 参数:o - 这是要检查在此队列中是否出现的对象。指定者:ArrayBlockingQueue 类 contains() 方法由:contains() 指定...
阅读 2 分钟
Java ArrayBlockingQueue 类的 size() 方法返回 ArrayBlockingQueue 中元素的总数。语法:public int size() 参数:NA 指定者:ArrayBlockingQueue 类 size() 方法由:Collection<E> 接口中的 Size。AbstractCollection<E> 类中的 Size。返回值:size() 方法返回此队列中元素的总数。示例...
阅读 3 分钟
Java ArrayBlockingQueue 的 toString() 方法返回此集合的字符串表示形式。语法:public String toString() 参数:NA 覆盖了 AbstractionCollection<E> 类中的 toString()。返回值:toString() 方法返回此集合的字符串表示形式。示例 1 import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.BlockingQueue; public class ArrayBlockingQueueToStringExample1 { public static void main(String[] args) { ...
阅读 2 分钟
Java ArrayBlockingQueue 类的 removeIf() 方法移除 ArrayBlockingQueue 中满足给定谓词过滤器(predicate filter)的元素。语法:public boolean removeIf(Predicate<? Super E> filter) 参数:参数 filter 是一个谓词,它对要移除的元素返回 true。指定者:ArrayBlockingQueue 类 removeIf() 方法...
阅读 3 分钟
我们请求您订阅我们的新闻通讯以获取最新更新。
我们提供所有技术(如 Java 教程、Android、Java 框架)的教程和面试问题
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India