UTF-8 and charcters in Java and Eclipse IDE -
public static void main(string[] args) throws unsupportedencodingexception { string str = "अ"; byte[] bytes = str.getbytes("utf-8"); (byte b : bytes) { system.out.print(b + "\t"); } string hindi = new string(bytes, "utf-8"); system.out.println("\nhindi = " + hindi); system.out.println((int) 'अ'); }
output:
-32 -92 -123 hindi = अ 2309
i need explanation on 3 outputs. last one.
also, copy paste characterअ
web page. how type manually in eclipse ide? example, alt + 65 give 'a' alt + 2309 not give me 'अ' (i copy paste again).
the first print:
see public byte[] getbytes(charset charset):
encodes string sequence of bytes using given charset, storing result new byte array.
the second print:
see public string(byte[] bytes, charset charset):
constructs new string decoding specified array of bytes using specified charset.
the third print:
see this link:
you're printing decimal code of it, 2309.
the links provided above should understand output you're getting in each case.
Comments
Post a Comment