Here you can find the source of toJava(CharSequence str)
public static String toJava(CharSequence str)
//package com.java2s; //License from project: Apache License public class Main { public static String toJava(CharSequence str) { if (str == null) return "null"; int len = str.length(); StringBuilder buf = new StringBuilder(len + 10); buf.append("\""); for (int i = 0; i < len; i++) { char c = str.charAt(i); switch (c) { case '\b': buf.append("\\b"); break; case '\f': buf.append("\\f"); break; case '\n': buf.append("\\n"); break; case '\r': buf.append("\\r"); break; case '\t': buf.append("\\t"); break; // case '\'': // buf.append("\\\'"); // break; case '\"': buf.append("\\\""); break; case '\\': buf.append("\\\\"); break; default: if (c >= ' ' && c < 128) { // ASCII buf.append(c);//from w ww . ja v a 2 s . co m } else { // Unicode buf.append(String.format("\\u%04x", (int) c)); } } } buf.append("\""); return buf.toString(); } }