Here you can find the source of unicodeEscape(String s)
public static String unicodeEscape(String s)
//package com.java2s; //License from project: BSD License public class Main { public static String unicodeEscape(String s) { StringBuffer sb = new StringBuffer(); for (int i = 0; i < s.length(); i++) { char c = s.charAt(i); sb.append(unicodeEscape(c)); }/*from w w w . j a v a 2s . c om*/ return sb.toString(); } /** * Converts the string to the unicode format '\u0020'. * * This format is the Java source code format. * * <pre> * UnicodeUtils.unicodeEscape(' ') = "\u0020" * UnicodeUtils.unicodeEscaped('A') = "\u0041" * </pre> * * @param ch the character to convert * @return the escaped unicode string */ public static String unicodeEscape(char ch) { if (ch < 0x10) { return "\\u000" + Integer.toHexString(ch); } else if (ch < 0x100) { return "\\u00" + Integer.toHexString(ch); } else if (ch < 0x1000) { return "\\u0" + Integer.toHexString(ch); } return "\\u" + Integer.toHexString(ch); } }