change specific index of string java code example Example: java replaceall single character .replaceAll("(?<!\\S)[^ ](?!\\S)", " ").trim()