Java Collections checkedSet() Method21 Mar 2025 | 2 min read The checkedSet() is an inbuilt method of Java Collections class. This method is used to get a dynamically typesafe view of the specified Set. SyntaxFollowing is the declaration of checkedSet() method: Parameter
ReturnsThe checkedSet() method automatically returns a dynamically typesafe view of the specified Set in the ascending order. ExceptionsClassCastException Compatibility VersionJava 1.5 and above Example 1Output: Type safe view of the Set is: [Hindi100, JavaTpoint, JavaTraining, SSSIT] Example 2Output: The view of the Set is: [500, 900, 1100, 2200] Example 3Output: Dynamic type safe view of Set is: [1800, 1500, 1100] 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$CheckedCollection.add(Collections.java:3081) at myPackage.CollectionCheckedSetExample3.main(CollectionCheckedSetExample3.java:12) Next TopicJava Collections Class |
Java collection class is used exclusively with static methods that operate on or return collections. It inherits Object class. The important points about are: Java Collection class supports the polymorphic algorithms that operate on collections. Java Collection class throws a NullPointerException if the collections or class objects provided...
6 min read
Java Collections Method The method of Java Collections class is used to replace all occurrences of one specified value in a list with the other specified value. Syntax Following is the declaration of method: public static <T> boolean replaceAll(List<T> list, T oldVal, T newVal) Parameter Parameter Description Required/Optional list It...
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 sorted map. Syntax Following is the declaration of method: public static <K,V> SortedMap<K,V> checkedSortedMap(SortedMap<K,V> m, Class<K> keyType, Class<V> valueType) Parameter Parameter Description Required/Optional m It is the...
3 min read
Java Collections Method The is a method of Java Collections class which adds all of the specified elements to the specified collection. The elements to be added may be specified individually or as an array. Syntax Following is the declaration of method: public static <T> boolean...
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 sorted set. Syntax Following is the declaration of method: public static <E> SortedSet<E> checkedSortedSet(SortedSet<E> s, Class<E> type) Parameter Parameter Description Required/Optional s It is the sorted set...
2 min read
Java Collections Method The is an inbuilt method of Java Collections class which returns the position of the object in a sorted list. There are two different types of Java collections method which can be differentiated depending on its parameter. These are: Java Collections binarySearch(List<?...
5 min read
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 the sorted Set that has no elements. These empty Set are immutable in nature. Syntax Following is the declaration of method: public static final <E> SortedSet<E> Parameter This method does not accept any parameter. 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 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 swap the elements at the specified positions in the specified list. Syntax Following is the declaration of method: public static void swap(List<?> list, int i, int j) Parameter Parameter Description Required/Optional list It is the list in which we will...
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