String strOrig = " ";
String strRes = <.. - ..>;
assert strRes.equals(" ");
String strRes = (new Object() {
public String work(String string) {
/* */
}
}).work(strOrig);
String strRes = String.format(strOrig.replaceAll("\\b(\\S)", "%S"), (Object[]) strOrig.replaceAll("\\b(\\S)\\S*", "$1").split("\\s+"));
String strRes = (" " + strOrig)
.replaceAll(
"\\s\\S+",
"$0 " + strOrig
.replaceAll("\\s", "")
.replaceAll("\\\\", "\\\\\\\\")
.replaceAll("\\$", "\\\\\\$")
.toUpperCase()
)
.replaceAll("(?i)(\\s)(\\S)(\\S*) \\S*(\\2)(\\S*)", "$1$4$3")
.substring(1);
Source: https://habr.com/ru/post/72461/