The Java code defines a class named RemoveAllElements that demonstrates how to clear all elements from a queue using the clear() method. Here's a step-by-step explanation of the code:
import java.util.LinkedList; import java.util.Queue; public class RemoveAllElements { public static void main(String[] args) { Queue <String> queue_list = new LinkedList <>(); queue_list.add("Yellow"); queue_list.add("Green"); queue_list.add("Pink"); queue_list.add("Black"); queue_list.add("Blue"); queue_list.add("White"); System.out.println("Queue Elements Before Clearing : " + queue_list); // Clear the queue queue_list.clear(); System.out.println("Queue Elements After Clearing : " + queue_list); } }
Queue Elements Before Clearing : [Yellow, Green, Pink, Black, Blue, White] Queue Elements After Clearing : []
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions