CODE
class StringGetBytesDemo
{
public static void main(String arg[])
{
String input = new String("Merit Campus");
try {
byte[] bytes = input.getBytes(); // LINE A
System.out.print("After encoding : ");
for (byte b : bytes)
System.out.print(b + " ");
System.out.println();
System.out.print("After encoding : ");
bytes = input.getBytes("UTF-8"); // LINE B
for (byte b : bytes)
System.out.print(b + " ");
System.out.println();
System.out.print("After encoding : ");
bytes = input.getBytes("ISO-8859-1"); // LINE C
for (byte b : bytes)
System.out.print(b + " ");
} catch (Exception e) {
System.out.println("Unsupported character set");
}
}
}
After encoding : 77 101 114 105 116 32 67 97 109 112 117 115
After encoding : 77 101 114 105 116 32 67 97 109 112 117 115
After encoding : 77 101 114 105 116 32 67 97 109 112 117 115
At LINE A,
the given string "Merit Campus"
is encoded using the default charset.
At LINE B,
the given string "Merit Campus"
is encoded using the "UTF-8"
charset.
At LINE C,
the given string "Merit Campus"
is encoded using the "ISO-8859-1"
charset.
"Merit Campus ‰"
with the above charsets. UTF-16
, UTF-16BE
, UTF-16LE
, UTF-32
, ISO-8859-2
, ISO-8859-4
, ISO-8859-5
.