How to convert String to Byte in Java?
Written on
February 27, 2009 at 6:38 am by
mkyong
Here i demonstrate how do convert a String to a Byte variable with String’s getBytes() function.
public class TestByte { public static void main(String[] argv) { String example = "This is an example"; byte[] bytes = example.getBytes(); System.out.println("Text : " + example); System.out.println("Text [Byte Format] : " + bytes); } }
Output
Text : This is an example Text [Byte Format] : [B@187aeca


