convert string to byte in Java

convert string to byte in Java
refe‮:ot r‬lautturi.com
/**
 * @author lautturi.com
 * Java example: converting string to bytes array 
 */

import java.util.*;
import java.text.ParseException;
import java.text.SimpleDateFormat;

public class Lautturi {

	public static void main(String[] args) {

		String str = "hello lautturi";
		byte[] bytes = str.getBytes();
		System.out.println("Array " + bytes);
		System.out.println("Array as String" + Arrays.toString(bytes));

	}
}

output:

Array [B@7b1d7fff
Array as String[104, 101, 108, 108, 111, 32, 108, 97, 117, 116, 116, 117, 114, 105]

104 is the ascii code of 'h'.

Created Time:2017-09-03 21:39:43  Author:lautturi