java replaceall single character

Java
.replaceAll("(?<!\\S)[^ ](?!\\S)", " ").trim()
Source

Also in Java: