how-to

Conversion between types

How to convert string to byte[] array

For conversion use method java.lang.String.getBytes():

String s = "This is text";
    
char[] bytes = s.getBytes();
    
System.out.println( Arrays.toString( bytes ) );
The output is:
[84, 104, 105, 115, 32, 105, 115, 32, 116, 101, 120, 116]
In method java.lang.String.getBytes() you can optionally set default charset.