Open In App

CharsetDecoder charset() in Java with examples

Last Updated : 23 Jul, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

CharsetDecoder.charset() is an in-built method in Java of CharsetDecoder class that returns the charset that created this decoder.

Syntax:

public final Charset charset()

Parameter: The function does not accepts any parameter.

Return value: The function returns the decoder’s charset.

Program below demonstrate the above mentioned function:

Program 1:




// Java program below demonstrate
// CharsetDecoder.charset function
  
import java.nio.charset.Charset;
import java.nio.charset.CharsetDecoder;
  
public class Main {
    public static void main(String[] argv) throws Exception
    {
        Charset charset = Charset.forName("ISO-8859-1");
  
        // initialising CharsetDecoder cd
        CharsetDecoder cd = charset.newDecoder();
        // print charset of decoder cd
        System.out.println(cd.charset());
    }
}


Output:

ISO-8859-1

Program 2:




// Java program below demonstrate
// CharsetDecoder.charset function
  
import java.nio.charset.Charset;
import java.nio.charset.CharsetDecoder;
  
public class Main {
    public static void main(String[] argv) throws Exception
    {
        Charset charset = Charset.forName("ISO-8859-2");
  
        // initialising CharsetDecoder cd
        CharsetDecoder cd = charset.newDecoder();
        // print charset of decoder cd
        System.out.println(cd.charset());
    }
}


Output:

ISO-8859-2


Similar Reads

java.nio.charset.Charset Class in Java
In Java, Charset is a mapping technique used in Java to map the 16-bit Unicode sequence and sequences of bytes. It is also used to encode and decode the string data text into different character encoding. It comes under java.nio.charset.Charset package. The charset must begin with a number or letter. Every charset can decode and encode. For constru
2 min read
CharsetDecoder averageCharsPerByte() method in Java with Examples
The averageCharsPerByte() method is a built-in method of the java.nio.charset.CharsetDecoder class which returns the average number of characters that will be produced for each byte of input. This heuristic value may be used to estimate the size of the output buffer required for a given input sequence. Syntax: public final float averageCharsPerByte
2 min read
CharsetDecoder maxCharsPerByte() method in Java with Examples
The maxCharsPerByte() method is a built-in method of the java.nio.charset.CharsetDecoder class which returns the maximum number of characters that will be produced for each byte of input. This value may be used to compute the worst-case size of the output buffer required for a given input sequence. Syntax: public final float maxCharsPerByte() Param
2 min read
CharsetDecoder isCharsetDetected() method in Java with Examples
The isCharsetDetected() method is a built-in method of the java.nio.charset.CharsetDecoder class which tells whether or not this decoder has yet detected a charset. The default implementation of this method always throws an UnsupportedOperationException. It should be overridden by auto-detecting decoders to return true once the input charset has be
2 min read
CharsetDecoder isAutoDetecting() method in Java with Examples
The isAutoDetecting() method is a built-in method of the java.nio.charset.CharsetDecoder class which tells whether or not this decoder implements an auto-detecting charset. Syntax: public boolean isAutoDetecting() Parameters: The function does not accepts any parameter. Return Value: The function returns a boolean value stating if this CharsetDecod
1 min read
CharsetDecoder detectedCharset() method in Java with Examples
The detectedCharset() method is a built-in method of the java.nio.charset.CharsetDecoder class which retrieves the charset that has been detected by this decoder. The default implementation of this method always throws an UnsupportedOperationException. It should be overridden by auto-detecting decoders to return true once the input charset has been
2 min read
CharsetDecoder replacement() method in Java with Examples
The replacement() method is a built-in method of the java.nio.charset.CharsetDecoder class returns this decoder's replacement value. The replacement value needs to be set inorder to get a valid replacement value. Syntax: public final Charset replacement() Parameters: The function does not accepts any parameter. Return Value: The function returns th
1 min read
CharsetDecoder malformedInputAction() method in Java with Examples
The malformedInputAction() method is a built-in method of the java.nio.charset.CharsetDecoder class which returns this decoder's current action for malformed-input errors. Syntax: public CodingErrorAction malformedInputAction() Parameters: The function does not accepts any parameter. Return Value: The function returns this decoder's current action
1 min read
CharsetDecoder unmappableCharacterAction() method in Java with Examples
The unmappableCharacterAction() method is a built-in method of the java.nio.charset.CharsetDecoder class which returns this decoder's current action for unmappable-character errors. Syntax: public CodingErrorAction unmappableCharacterAction() Parameters: The function does not accepts any parameter. Return Value: The function returns this decoder's
1 min read
CharsetDecoder reset() method in Java with Examples
The reset() method is a built-in method of the java.nio.charset.CharsetDecoder class which resets this CharsetDecoder and clears its internal state. Syntax: public final CharsetDecoder reset() Parameters: The function does not accepts any parameter. Return Value: The function returns this CharsetDecoder after resetting it. Below is the implementati
1 min read
Practice Tags :