Java String getBytes() Method
Java String getBytes()
The getBytes()
method encodes a specified String into a sequence of bytes using the named charset, storing the result into a new byte array.
Note: The behavior of this method, when this string cannot be encoded in the given charset, is unspecified.
Example
Output
Syntax
Parameter Values
Value | Type | Explanation |
---|---|---|
charset | Optional | Specifies the charset to encode this string into a sequence of bytes. |
charsetName | Optional | Specifies the named charset to encode this string into a sequence of bytes. |
Return Value
Value | Explanation |
---|---|
Byte | Returns the sequence of bytes. |
Java String getBytes(Charset charset)
Encodes this String into a sequence of bytes using the given charset, storing the result into a new byte array.
Example
Output
Java String getBytes(String charsetName)
Encodes this String into a sequence of bytes using the named charset, storing the result into a new byte array.
Example
Output
Reminder
Hi Developers, we almost covered 90% of String functions and Interview Question on Java with examples for quick and easy learning.
We are working to cover every Single Concept in Java.
Please do google search for:
Join Our Channel
Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.
This channel is primarily useful for Full Stack Web Developer.