Java tutorial
//package com.java2s; public class Main { public static String encodeUnicode(String str) { char[] utfBytes = str.toCharArray(); StringBuffer buffer = new StringBuffer(); for (int byteIndex = 0; byteIndex < utfBytes.length; byteIndex++) { String hexB = Integer.toHexString(utfBytes[byteIndex]); if (hexB.length() <= 2) { hexB = "00" + hexB; } buffer.append("\\u" + hexB); } return buffer.substring(0); } }