Charset isSupported() method in Java with Examples
The isSupported() method is a built-in method of the java.nio.charset checks if a given charset is supported or not.
public final boolean isSupported()
Parameters: The function accepts a single mandatory parameter charset Name which specifies the canonical name or the alias name which is to be checked.
Return Value: The function returns a boolean value. It returns true if it is supported, else it returns false.
Errors and Exceptions: The function throws two exceptions as shown below:
- IllegalCharsetNameException: It is thrown if the given charset name is illegal
- IllegalArgumentException : It is thrown if the given charset Name is null
Below is the implementation of the above function:
ISO-2022-CN is supported or not? :true
ISO is supported or not? :false
Exception is java.nio.charset.IllegalCharsetNameException:
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.