Convert a string into a byte array:
String |
The getBytes() method converts a string into a byte array.
The encoding of the bytes relies on the charset argument.
If the charset argument is omitted, the bytes will be encoded using the system’s default character set.
“Choose one from the following options:”
public |
public |
Parameter |
Description |
charset |
“This parameter is optional. It’s a Charset object specifying the character set to be used for encoding the string into bytes.” |
Returns: |
A byte array representing the bytes of the string with a specific encoding. |
Java version: |
“The charset parameter, introduced in version 1.6, can be of any type.” |