String.getBytes() has the following syntax.
public byte[] getBytes()
In the following code shows how to use String.getBytes() method.
import java.util.Arrays; public class Main { public static void main(String[] argv) { String str = " j a v a 2 s.com "; byte[] bytes = str.getBytes(); System.out.println(Arrays.toString(bytes)); } }
The code above generates the following result.