javaqueue清空_JavaDelayQueueclear()用法及代码示例

更新时间:2023-05-31 03:28:00 阅读: 评论:0

javaqueue清空_JavaDelayQueueclear()⽤法及代码⽰例Java中的DelayQueue的clear()⽅法⽤于删除当前DelayQueue对象中的所有元素。返回此调⽤后,队列将为空。延迟中没有过期的队列中的元素会⾃动从队列中丢弃。
句法:我的幸福作文
public void clear()七校联合办学
参数:此⽅法不带任何参数。
返回值:此⽅法不返回任何值。
以下⽰例程序旨在说明上述⽅法:
// Java program to illustrate the clear() method
// of DelayQueue class
import urrent.DelayQueue;
import urrent.Delayed;
import urrent.TimeUnit;
public class GFG {
public static void main(String args[])
{
// Create a DelayQueue instance
DelayQueue queue = new DelayQueue();
// Create an Object of type Delayed
Delayed obj = new Delayed() {
public long getDelay(TimeUnit unit)
广西习俗{
有气质带静的网名
return 24; // some value is returned
}
public int compareTo(Delayed o)
{
if (o.getDelay(TimeUnit.DAYS) >结肠功能紊乱
return 1;
el if (o.getDelay(TimeUnit.DAYS) ==
return 0;
return -1;
}两个月宝宝吐奶
};
// Add the obj to the queue
queue.add(obj);
// Check if queue is empty
谭晶
System.out.println("Is queue empty() : "
+ queue.isEmpty());
// Remove all elements from queue
// uing clear() method
queue.clear();
// Check if queue is empty
System.out.println("Is queue empty after calling clear() : " + queue.isEmpty());
}
}
输出:
Is queue empty() : fal
幼儿园教具Is queue empty after calling clear() : true

本文发布于:2023-05-31 03:28:00,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/82/817663.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:队列   元素   对象   没有   说明   网名   法及   联合
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图