java replace alternate character in string with another character code example Example: java replaceall single character .replaceAll("(?<!\\S)[^ ](?!\\S)", " ").trim()