Dec 072016

ADM

How to convert Byte array to String in Java

  • 07 December 2016
  • ADM

 

 

 

How to convert Byte array to String in Java - images/logos/java.jpg

 

It is very easy to convert byte[] array to string.

Example

package com.admfactory;

public class ByteArrayToString {

    public static void main(String[] args) {
	String sample = "Sample text.";

	/** byte array */
	byte[] array = sample.getBytes();

	String str = new String(array);

	System.out.println("byte[] array to String example.");
	System.out.println();
	System.out.println("array: " + array);
	System.out.println("string: " + str);
    }
}

Output

byte[] array to String example.

array: [B@4669b7fe
string: Sample text.

 

 

 

References