Java String quote( String str) Utility Method

Java String Utility Methods


This page contains the source code of Java String quote() utility method - This method quotes the given String with single quotes.

Java String quote( String str) Utility Method

The following String quote() utility method quotes the given String with single quotes:

/**
 * Quote the given {@code String} with single quotes.
 * @param str the input {@code String} (e.g. "myString")
 * @return the quoted {@code String} (e.g. "'myString'"),
 * or {@code null} if the input was {@code null}
 */

public static String quote( String str) {
 return (str != null ? "'" + str + "'" : null);
}



Comments