The Java code demonstrates how to use the Queue interface with the LinkedList class to add elements to a queue and then check if the queue contains a specific element using the contains() method.
import java.util.LinkedList; import java.util.Queue; public class QueueContainsElement { public static void main(String[] args) { Queue<Integer> queue = new LinkedList<>(); // Adding elements to the queue queue.add(10); queue.add(23); queue.add(2); queue.add(18); queue.add(17); // Checking if the queue contains a specific element int elecheck = 23; boolean ele = queue.contains(elecheck); if(ele) { System.out.println("The Queue Contains " + elecheck); } else { System.out.println("The Queue Does Not Contain " + elecheck); } } }
The Queue Contains 23
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions