What is the java equivalent of javascript String.fromCharCode?

What is javascript's java equivalent:

String.fromCharCode(n1, n2, ..., nX)

http://www.w3schools.com/jsref/jsref_fromCharCode.asp

+5
source share
1 answer

It will look something like this:

public static String fromCharCode(int... codePoints) {
    StringBuilder builder = new StringBuilder(codePoints.length);
    for (int codePoint : codePoints) {
        builder.append(Character.toChars(codePoint));
    }
    return builder.toString();
}

Please note that execution is charnot guaranteed because the code value may exceed the upper limit char(65535). charwas installed in the dark days of Java when Unicode 3.1 has not yet been released, which goes beyond 65535 characters.

: String , int[] ( Java 1.5, ), . :

public static String fromCharCode(int... codePoints) {
    return new String(codePoints, 0, codePoints.length);
}
+16

All Articles