I need to add some characters to a String before using it for an API call. The idea is to add a
" char both at the beginning and at the end of the String, to make sure the API does an exact search for the input string.
StringBuilder(escapeJava(query)) .insert(0, DOUBLE_QUOTE_CHAR) .append(DOUBLE_QUOTE_CHAR) .toString();
String.format("%c" + escapeJava(query) + "%c", DOUBLE_QUOTE_CHAR, DOUBLE_QUOTE_CHAR)
I prefer the readability of the first one, but I don't think it will be as quick as the second version, and might look like overkill.