Here you can find the source of toUnicode(String str)
public static String toUnicode(String str)
//package com.java2s; //License from project: Apache License public class Main { public static String toUnicode(String str) { char[] arChar = str.toCharArray(); int iValue = 0; String uStr = ""; for (int i = 0; i < arChar.length; i++) { iValue = (int) str.charAt(i); if (iValue <= 256) { // uStr+="& "+Integer.toHexString(iValue)+";"; uStr += "\\" + Integer.toHexString(iValue); } else { // uStr+="&#x"+Integer.toHexString(iValue)+";"; uStr += "\\u" + Integer.toHexString(iValue); }/* ww w . j a va2 s. co m*/ } return uStr; } }