Java String(byte[] bytes, String charsetName) Constructor

Syntax

String(byte[] bytes, String charsetName) constructor from String has the following syntax.

public String(byte[] bytes,  String charsetName)  throws UnsupportedEncodingException

Example

In the following code shows how to use String.String(byte[] bytes, String charsetName) constructor.


import java.io.UnsupportedEncodingException;
//from   w  w  w  .  j ava 2s.co  m

public class Main {
  public static void main(String[] argv) {
    byte[] bytes = new byte[]{65,66,67,68};
    try {
      System.out.println(new String(bytes,"ASCII"));
    } catch (UnsupportedEncodingException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    
  }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    java.lang »




Boolean
Byte
Character
Class
Double
Enum
Float
Integer
Long
Math
Number
Object
Package
Process
ProcessBuilder
Runnable
Runtime
SecurityManager
Short
StackTraceElement
StrictMath
String
StringBuffer
StringBuilder
System
Thread
ThreadGroup
ThreadLocal
Throwable