VOOZH about

URL: https://www.geeksforgeeks.org/java/java-collections-checkednavigableset-method-with-examples/

⇱ Java Collections checkedNavigableSet() Method with Examples - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Java Collections checkedNavigableSet() Method with Examples

Last Updated : 3 Jan, 2022

The checkedQueue() method of Java Collections is a method that returns a  dynamically and typesafe view of the given Set. Any attempt to insert an element of the wrong type will result in an immediate ClassCastException.

Syntax:

public static <E> NavigableSet<E> checkedNavigableSet(NavigableSet<E> set, Class<E> datatype)

Parameters:

  • set is an input set data
  • datatype is the type of elements that set can hold

Return Type: This method will return the dynamically and typesafe view of the given Set.

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: 


Output
[R, java, php/jsp, python]

Example 2:


Output
[1, 2, 3, 4]
Comment