Java Collections checkedQueue() Method21 Mar 2025 | 2 min read The checkedQueue() is a method of Java Collections class which returns a dynamically typesafe view of the specified Queue. If an element inserted of the wrong type, it will result in an immediate ClassCastException. SyntaxFollowing is the declaration of checkedQueue() method: Parameter
ReturnsThe checkedQueue() method returns a dynamically typesafe view of the specified Queue. ExceptionsClassCastException Compatibility VersionJava 1.8 and above Example 1Output: Type safe view of the Queue is: [A, B, C, D] Example 2Output: Type safe view of the Queue is: [55, 66, 66, 77, 88, 77] Example 3Output: [1, 2, 5] Exception in thread "main" java.lang.ClassCastException: Attempt to insert class java.lang.String element into collection with element type class java.lang.Integer at java.base/java.util.Collections$CheckedCollection.typeCheck(Collections.java:3038) at java.base/java.util.Collections$CheckedQueue.offer(Collections.java:3188) at myPackage.CollectionCheckedQueueExample3.main(CollectionCheckedQueueExample3.java:12) Next TopicJava Collections Class |
Java Collections Method The method of Java Collections class is used to get a synchronized (thread-safe) sorted map backed by the specified sorted map. Syntax Following is the declaration of method: public static <K,V> SortedMap<K,V> synchronizedSortedMap(SortedMap<K,V> m) Parameter Parameter Description Required/Optional m It is the sorted map which will be wrapped in...
2 min read
Java Collections Method The method of Java Collections class is used to get an unmodifiable view of the specified set. Syntax Following is the declaration of method: public static <T> Set<T> unmodifiableSet(Set<? extends T> s) Parameter Parameter Description Required/Optional s It is the set for which an unmodifiable view is to be...
2 min read
Java Collections Method The method of Java Collections class returns an empty sorted map which is immutable. Syntax Following is the declaration of method: public static final <K,V> SortedMap<K,V> Parameter This method does not accept any parameter. Returns The method returns an empty immutable Sorted Map. Exceptions NA Compatibility Version Java 1.8...
1 min read
Java Collections Method The method of Java Collections class is used to get a synchronized (thread-safe) collection backed by the specified collection. Syntax Following is the declaration of method: public static <T> Collection<T> synchronizedCollection(Collection<T> c) Parameter Parameter Description Required/Optional c It is the collection to be "wrapped" in a synchronized collection. Required Returns The ...
2 min read
Java Collections Method The method of Java Collections class returns an empty navigable map which is immutable. Syntax Following is the declaration of method: public static final <K,V> NavigableMap<K,V> Parameter This method does not accept any parameter. Returns The method returns an empty immutable Navigable Map. Exceptions NA Compatibility Version Java...
2 min read
Java Collections Method The method of Java Collections class copies all of the elements from one list into another list. In this method, the size of the destination list must be greater than or equal to the size of the source list. Syntax Following is the...
3 min read
Java Collections Method The method of Java Collections class is used to reverse the order of the elements in the specified list. Syntax Following is the declaration of method: public static void reverse(List<?> list) Parameter Parameter Description Required/Optional list It is the list whose elements are to be reversed. Required Returns The method does...
2 min read
Java Collections Method The method of Java Collections class is used to replace all of the elements of the specified list with the specified elements. This method filled all the elements with the same values. Syntax Following is the declaration of method: public static <T> void...
2 min read
Java Collections Method The heckedNavigableMap() is an inbuilt method of Java Collections class. This method is used to get a dynamically typesafe view of the specified Navigable Map. If there is any attempt of insert mapping whose key or value has the wrong type, it...
3 min read
Java Collections Method The method of Java Collections class is used to get an enumeration that has no elements. Syntax Following is the declaration of method: public static <T> Enumeration<T> Parameter This method does not accept any parameter. Returns The method returns an empty enumeration. Exceptions NA Compatibility Version Java 1.7...
2 min read
We request you to subscribe our newsletter for upcoming updates.
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India