网上教育平台哪个好
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) ==
williamsreturn 0;
return -1;
}
bend是什么意思
go back home
};chdir
// 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());
}
}
输出:
modify是什么意思Is queue empty() : fal
Is queue empty after calling clear() : true