Java Charset.forName(String charsetName)

Syntax

Charset.forName(String charsetName) has the following syntax.

public static Charset forName(String charsetName)

Example

In the following code shows how to use Charset.forName(String charsetName) method.


/* ww w  .j av  a2  s. co  m*/
import java.nio.charset.Charset;

public class Main {

  public static void main(String[] args) {
    
      Charset cs = Charset.forName("US-ASCII");
      System.out.println(cs.displayName());
      System.out.println(cs.toString());

  }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    java.nio.charset »




Charset
CharsetDecoder
CharsetEncoder
StandardCharsets