Java Collections checkedMap() Method21 Mar 2025 | 2 min read The checkedMap() is an inbuilt method of Java Collections class. This method is used to get a dynamically typesafe view of the specified Map. If any attempt of insert mapping whose key or value has the wrong type, it will result in an immediate ClassCastException. SyntaxFollowing is the declaration of checkedMap() method: Parameter
ReturnsThe checkedMap() method returns a dynamically typesafe view of the specified Map. ExceptionsClassCastException Compatibility VersionJava 1.5 and above Example 1Output: Type safe view of the Map is: {A=11, B=12, C=13, V=14} Example 2Output: Map Element: {1=One, 2=Two, 3=Three} {1=One, 2=Two, 3=Three, Four=4} Example 3Output: Map content: {Rahul=3, Amit=4, Raj=1, TpointTech=2} Exception in thread "main" java.lang.ClassCastException: Attempt to insert class java.lang.Integer key into map with key type class java.lang.String at java.base/java.util.Collections$CheckedMap.typeCheck(Collections.java:3575) at java.base/java.util.Collections$CheckedMap.put(Collections.java:3621) at myPackage.CollectionCheckedMapExample3.main(CollectionCheckedMapExample3.java:13) Next TopicJava Collections Class |
Java Collections Method The is a method of Java Collections class which is used to get the enumeration over the specified collection. Syntax Following is the declaration of method: public static <T> Eenumeration<T> enumeration(Collection<T> c) Parameter Parameter Description Required/Optional c It is a collections for which enumeration is to be returned. Required Returns The ...
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
Java Collections Method The method of Java Collections class is used to get a synchronized (thread-safe) collection backed by the specified list. Syntax Following is the declaration of method: public static <T> List<T> synchronizedList(List<T> list) Parameter Parameter Description Required/Optional list It is the list which will be wrapped in a synchronized list. Required Returns The...
2 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 is an inbuilt method of Java Collections class which returns a view of a Deque as a Last-in-first-out (LIFO) Queue. In this method, the method add and remove is mapped to push and pop operation respectively. It is useful when...
2 min read
Java Collections Method The method of Java Collections class is used to get a synchronized (thread-safe) map backed by the specified map. Syntax Following is the declaration of method: public static <K,V> Map<K,V> synchronizedMap(Map<K,V> m) Parameter Parameter Description Required/Optional m It is the map which will be wrapped in a synchronized map. Required Returns The...
2 min read
Java Collections Method The is an inbuilt method of Java Collections class. This method is used to get a dynamically typesafe view of the specified Set. Syntax Following is the declaration of method: public static <E> Set<E> checkedSet(Set<E> s, Class<E> type) Parameter Parameter Description Required/Optional s It is the set for which...
2 min read
Java Collections Method The method of Java Collections class is used to get a synchronized (thread-safe) navigable map backed by the specified navigable map. Syntax Following is the declaration of method: public static <K,V> NavigableMap<K,V> synchronizedNavigableMap(NavigableMap<K,V> m) Parameter Parameter Description Required/Optional m It is the navigable map which will be wrapped in...
2 min read
Java Collections Method The method of Java Collections class is used to return a set backed by the specified map. The resulting set displays the same ordering, concurrency, and performance characteristics as the backing map. Syntax Following is the declaration of method: public static <E> Set<E>...
2 min read
Java Collections Method The 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. Syntax Following is the declaration of method: public static <E>...
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