Java Utililty Methods Unicode Create

List of utility methods to do Unicode Create

Description

The list of methods to do Unicode Create are organized into topic(s).

Method

StringtoUnicodeRepresentation(String str)
to Unicode Representation
if (str == null)
    return str;
StringBuilder unicodeString = new StringBuilder();
for (int i = 0; i < str.length(); i++) {
    char ch = str.charAt(i);
    if ((ch >= 0x0020) && (ch <= 0x007e)) {
        unicodeString.append(ch);
    } else {
...
StringtoUnicodeStr(int i)
to Unicode Str
char c1 = Integer.toHexString((i >> 12) & 0x0000000F).charAt(0);
char c2 = Integer.toHexString((i >> 8) & 0x0000000F).charAt(0);
char c3 = Integer.toHexString((i >> 4) & 0x0000000F).charAt(0);
char c4 = Integer.toHexString((i) & 0x0000000F).charAt(0);
return "\\u" + c1 + c2 + c3 + c4;
StringtoUnicodeString(byte[] ba)

Similar to the toString() method except that the Unicode escape character is inserted before every pair of bytes.

return toUnicodeString(ba, 0, ba.length);
StringtoUnicodeString(byte[] data)
to Unicode String
return new String(data, "UTF-8");
StringtoUnicodeString(char c)
to Unicode String
StringBuilder response = new StringBuilder();
String resp = Integer.toHexString(c);
for (int i = 0; i < 4 - resp.length(); i++) {
    response.append(0);
response.append(resp);
return response.toString();
StringtoUnicodeString(char[] chars)
to Unicode String
StringBuffer strBuf = new StringBuffer();
for (int i = 0; i < chars.length; i++) {
    strBuf.append("\\u").append(Integer.toHexString(chars[i]));
return strBuf.toString();
StringtoUnicodeString(String baseString)
to Unicode String
return toUnicodeString(baseString, "\\u");
StringtoUnicodeString(String s)
to Unicode String
StringBuffer sb = new StringBuffer();
for (int i = 0; i < s.length(); i++) {
    char c = s.charAt(i);
    if (c >= 0 && c <= 255) {
        sb.append(c);
    } else {
        sb.append("\\u" + Integer.toHexString(c));
return sb.toString();
StringtoUnicodeString(String str)
to Unicode String
String unicode = "";
char[] charAry = new char[str.length()];
for (int i = 0; i < charAry.length; ++i) {
    charAry[i] = str.charAt(i);
    unicode = unicode + "\\u" + Integer.toString(charAry[i], 16);
return unicode;
StringtoUnicodeSymbols(String s)
Translate the specified string to UNICODE presented code string.
StringBuffer sb = new StringBuffer();
char a[] = s.toCharArray();
for (char c : a)
    if (c < 256)
        sb.append(c);
    else if (c < 4096)
        sb.append(String.format("\\u0%h", (int) c));
    else
...