VOOZH about

URL: https://www.geeksforgeeks.org/java/charset-issupported-method-in-java-with-examples/

⇱ Charset isSupported() method in Java with Examples - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Charset isSupported() method in Java with Examples

Last Updated : 1 Dec, 2020

The isSupported() method is a built-in method of the java.nio.charset checks if a given charset is supported or not. 

Syntax:  

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:

Program 1:  


Output: 
ISO-2022-CN is supported or not? :true

 

Program 2: 


Output: 
ISO is supported or not? :false

 

Program 3: 


Output: 
Exception is java.nio.charset.IllegalCharsetNameException:

 

Reference: https://docs.oracle.com/javase/9/docs/api/java/nio/charset/Charset.html#isSupported-java.lang.String-
 

Comment