![]() |
VOOZH | about |
In Java, the process of converting a String to a certain character encoding is converting the string's character sequence to a byte array and applying the chosen character encoding.
Using the String class's getBytes() function to transform a string into a byte array is the fundamental idea. The Charset class also allows you to define the character encoding. An overloaded version of the getBytes() function accepts a Charset as a parameter.
public byte[] getBytes()Below is the implementation to Convert a String to a specific character encoding in Java:
Original String: Hello, Rahul! UTF-8 Encoded Bytes: 48 65 6C 6C 6F 2C 20 52 61 68 75 6C 21
The Program is divided it in different section: