Java Utililty Methods String Quote

List of utility methods to do String Quote

Description

The list of methods to do String Quote are organized into topic(s).

Method

StringquoteIfNotNull(String str)
quote If Not Null
return str = (str != null) ? str = "'" + escapeApostrophe(str) + "'" : null;
StringquoteIfNotNull(String text)
quote If Not Null
return (text != null ? "'" + text + "'" : text);
voidquoteIfNotNull(StringBuilder sb, String val)
quote If Not Null
if (val == null)
    sb.append("null");
else
    sb.append("'").append(val).append("'");
ObjectquoteIfString(Object obj)
quote If String
return (obj instanceof String) ? quote((String) obj) : obj;
ObjectquoteIfString(Object obj)
Turn the given Object into a String with single quotes if it is a String; keeping the Object as-is else.
return (obj instanceof String ? quote((String) obj) : obj);
Object[]quoteIfString(Object... arguments)
quote If String
Object[] result = new Object[arguments.length];
for (int i = 0; i < arguments.length; i++) {
    result[i] = quoteIfString(arguments[i]);
return result;
StringquoteImpl(String s, char delim)
quote Impl
if (s == null)
    return null;
StringBuffer sb = new StringBuffer(s.length() + 3); 
sb.append(delim);
for (int i = 0; i < s.length(); i++) {
    char c = s.charAt(i);
    if (c == delim)
        sb.append(delim);
...
StringquoteIt(String orig)
Quote it.
String result = replace(orig, " ", "\\ ");
return result;
StringquoteJava(String s)
Convert string to Java-compatible source form.
StringBuilder b = new StringBuilder();
b.append('"');
quoteJavaContent(s, b);
b.append('"');
return b.toString();
StringquoteJavascriptString(String s)
quote Javascript String
s = s.replaceAll("\\\\", "\\\\\\\\").replaceAll("\"", "\\\\\"");
return quote(s);