Java Data Type Tutorial - Java String(byte[] bytes, int offset, int length, Charset charset) Constructor








Syntax

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

public String(byte[] bytes,  int offset,  int length,  Charset charset)

Example

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

import java.nio.charset.Charset;
//  w  w  w. ja v  a  2s  .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,1,3, Charset.forName("ASCII")));
    
  }
}

The code above generates the following result.