The Java code defines a class ClearQueue with a method clearQueue that clears all elements from a given Queue of integers.
import java.util.*; public class ClearQueue { public static void clearQueue(Queue<Integer> queue) { queue.clear(); } public static void main(String[] args) { Queue<Integer> queue = new LinkedList<>(); queue.offer(1); queue.offer(2); queue.offer(3); queue.offer(4); queue.offer(5); System.out.println("Original Queue : " + queue); clearQueue(queue); System.out.println("Cleared Queue : " + queue); } }
Original Queue : [1, 2, 3, 4, 5] Cleared Queue : []
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions