I there a Java equivalent to the Objective-C stringWithUTF8String:?
I need to convert the following from Objective-开发者_StackOverflowC to Java:
char key[] = {'9' + 1, 'U' + 2, '6' + 3, 'S' + 4, '7' + 5} return [NSString stringWithUTF8String:key]
I'm not sure how to go about this.. does anyone have any ideas?
Yes, public String(byte[] bytes, Charset charset), the constructor of String that receives char[] and charset as parameters.
You use the public String(byte[] bytes, String charsetName) constructor and pass "UTF-8" as the charset. Here is an example:
byte key[] = {'9' + 1, 'U' + 2, '6' + 3, 'S' + 4, '7' + 5};
return new String(key, "UTF-8");
精彩评论