Java Collections checkedQueue() Method with Examples Last Updated : 03 Jan, 2022 Summarize Comments Improve Suggest changes Share Like Article Like Report The checkedQueue() method of Java Collections is a method that returns a dynamically and typesafe view of the given Queue. Any attempt to insert an element of the wrong type will result in an immediate ClassCastException. Syntax: public static <E> Queue<E> checkedQueue(Queue<E> queue, Class<E> type) Parameters: queue is the queue that is returned for dynamically safetype is the data type of the queue elements Return Type: This method will return the dynamically and typesafe view of the given Queue. Exceptions: ClassCastException: ClassCastException is a runtime exception raised in Java when we try to improperly cast a class from one type to another. Example 1: Create a type-safe view of the List using checkedQueue() Method Java // Java Program to Create a // type-safe view of the List // using checkedQueue() Method import java.util.*; public class GFG { // main method public static void main(String[] args) { // create a queue Queue<String> data = new PriorityQueue<String>(); // add elements data.add("Python"); data.add("R"); data.add("C"); data.add("Java/jsp"); // Create type safe view of the List System.out.println( Collections.checkedQueue(data, String.class)); } } Output[C, Java/jsp, Python, R] Example 2: Java import java.util.*; public class GFG { // main method public static void main(String[] args) { // create a queue Queue<Integer> data = new PriorityQueue<Integer>(); // add elements data.add(1); data.add(23); data.add(56); data.add(21); // Create type safe view of the List System.out.println( Collections.checkedQueue(data, Integer.class)); } } Output[1, 21, 56, 23] Comment More infoAdvertise with us Next Article Collections asLifoQueue() method in Java with Examples S sireeshakanneganti112 Follow Improve Article Tags : Java Java-Functions Java-Collections-Class Practice Tags : Java Similar Reads Collections checkedList() method in Java with Examples The checkedList() method of Collections class is present inside java.util package is used to return a dynamically typesafe view of the specified list. The key thing to note here is that the returned list will be serializable if the specified list is serializable. Since null is considered to be a val 3 min read Collections asLifoQueue() method in Java with Examples The asLifoQueue() method of java.util.Collections class is used to return a view of a Deque as a Last-in-first-out (Lifo) Queue. Method add is mapped to push, remove is mapped to pop and so on. This view can be useful when you would like to use a method requiring a Queue but you need Lifo ordering.E 2 min read BlockingQueue contains() method in Java with examples The contains(Object o) method of BlockingQueue interface checks if the passed element in the parameter exists in the container or not. It returns true if the element exists in the container else it returns a false value. Syntax: public boolean contains(Object o) Parameters: This method accepts a man 2 min read AbstractQueue clear() method in Java with examples The clear() method of AbstractQueue removes all of the elements from this queue. The queue will be empty after this call returns. Syntax: public void clear() Parameters: This method does not accept any parameters. Returns: The method does not returns anything. Below programs illustrate clear() metho 1 min read AbstractQueue element() method in Java with examples The element() method of AbstractQueue retrieves, but does not remove, the head of this queue. Syntax: public E element() Parameters: This method does not accept any parameters. Returns: The method returns the head of the Queue. Exception: The function throws an NoSuchElementException if the queue is 1 min read DelayQueue drainTo() method in Java with Examples The drainTo(Collection<E> c) method of DelayQueue removes all available elements from this DelayQueue and adds them to the given collection passed as a parameter. This method is more efficient than repeatedly polling this DelayQueue. There are also possibilities of failure. If a DelayQueue att 6 min read Like