Java String(byte[] bytes, Charset charset) Constructor

Syntax

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

public String(byte[] bytes,  Charset charset)

Example

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


import java.nio.charset.Charset;
/*  w  w w  .  j av a  2 s. c o  m*/


public class Main {
  public static void main(String[] argv) {
    byte[] bytes = new byte[]{65,66,67,68};
    System.out.println(new String(bytes, Charset.forName("ASCII")));
    
  }
}

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