unicode to String - Java java.lang

Java examples for java.lang:String Unicode

Description

unicode to String

Demo Code


//package com.java2s;

public class Main {
    public static void main(String[] argv) throws Exception {
        String uniStr = "java2s.com";
        System.out.println(unicode2String(uniStr));
    }/*  ww w. j a  v  a2s  . co  m*/

    public static String unicode2String(String uniStr) {
        StringBuilder sb = new StringBuilder();
        String[] hex = uniStr.split("\\\\u");
        int len = hex.length;
        for (int i = 0; i < len; i++) {

            int data = Integer.parseInt(hex[i], 16);

            sb.append((char) data);
        }
        return sb.toString();
    }
}

Related Tutorials