Replace the string:
If you want to specify which part of the string replacement operation is required:
-
public String replace(CharSequence oldStr,CharSequence newStr)
-
All portions of the string replaced oldStr specified newStr
-
oldStr representatives need to replace the old string section
-
newStr new representatives to replace the string section
-
This method returns a value
-
CharSequence parameter type is simply finds the string String.
-
Contents of the string does not change, so the return value and replace methods result is a new string.
public class Demo04StringReplace {
public static void main(String[] args) {
String str1 = "How do you do";
String str2= str1.replace("o", "*");
System.out.println(str1); //How do you do
System.out.println(str2); //H*w d* y*u d*
String str3 = "会不会玩啊?你大爷!真是服了";
String str4 = str3.replace("你大爷", "***");
System.out.println(str4);
}
}