1. Java String replace() Overview
In tutorial, We'll learn about Java String replace() method and explanation with examples. replace() method is used to replace a character with another character in a String and this method returns a new string after replacing characters.
In previous tutorial, We've seen How to use Java 11 String API repeat() method.
1.1 Syntax
public String replace(char oldChar, char newChar) public String replace(CharSequence target, CharSequence replacement)
replace() method is available in two variants. First variant takes two char's as input and replace a char by a new char. Where as in second variant, It takes two CharSequence as arguments and replace one CharSequence by new CharSequence.
Here, CharSequence means String, StringBuffer, StringBuilder. Any one of these can be passed as arguments to the second variant of replace().