java string replace all sentence characters code example Example: java replaceall single character .replaceAll("(?<!\\S)[^ ](?!\\S)", " ").trim()