what is the difference between (char)temp and Character.toChars(temp) and String.valueOf(Character.toChars(temp)) in java -
i got same result these, difference? better? temp int, read reader.read()
system.out.print((char)temp); system.out.print(character.tochars(temp)); system.out.print(string.valueof(character.tochars(temp)));
normally, these 3 statements same thing. , certainly, case if temp contains character have read using reader.read() , character not utf-16 surrogate character. (whether "right" thing or not depends on whether default character encoding supports character trying write.)
if temp contained unicode codepoint larger 65535, first statement end mangling codepoint, second , third statements result in correct representation of character being output ... modulo default character set issue.
if temp contained utf-16 surrogate character, i'm not quite sure happen. suspect work. however, literal reading of javadoc printstream.print(char) leaves open possibility utf-16 utf-8 conversion might treat single surrogate character error. however, moot unless reader reading stream included unicode codepoints larger 65535.
Comments
Post a Comment