Computer science Java String replace() method replaces every occurrence of a given character with a new character and returns a new string. The Java replace() string method allows the replacement of a sequence of character values. Java String ReplaceAll() method finds all occurrences of a sequence of characters matching a regular expression and replaces them with the replacement string. At the end of the call, a new string is returned by the function replaceAll() in Java. Java String replaceFirst() method replaces ONLY the first substring which matches a given regular expression. Matching of the string starts from the beginning of a string (left to right). At the end of the call, a new string is returned by the Java replaceFirst() function.