import java.util.concurrent.*; public class Example { public static void main(String[] args) { BlockingQueuequeue = new ArrayBlockingQueue<>(10); queue.add("one"); queue.add("two"); queue.add("three"); System.out.println(queue.isEmpty()); // false queue.clear(); System.out.println(queue.isEmpty()); // true } }
import java.util.concurrent.*; public class Example { public static void main(String[] args) { BlockingQueueIn this example, we create an instance of the LinkedBlockingQueue and add two integers to it using the offer() method. We then use the while loop to iterate over the queue until it is empty. Within the while loop, we use the poll() method to remove and print elements from the queue. Therefore, the java.util.concurrent package library contains the BlockingQueue interface.queue = new LinkedBlockingQueue<>(); queue.offer(5); queue.offer(10); while (!queue.isEmpty()) { System.out.println(queue.poll()); } } }