java update string at position code example Example: java replaceall single character .replaceAll("(?<!\\S)[^ ](?!\\S)", " ").trim()