代码之家  ›  专栏  ›  技术社区  ›  jon077

java与javascript的String.fromCharCode等价于什么?

  •  6
  • jon077  · 技术社区  · 15 年前

    它是java与javascript的等价物:

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

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

    1 回复  |  直到 15 年前
        1
  •  20
  •   BalusC    15 年前

    可能是这样的:

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

    注意铸造到 char 烧焦 (65535). 这个 烧焦 Unicode 3.1

    更新 :的 String 实际上 a constructor taking an int[]

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