温馨提示×

replaceAll是否支持链式调用

小樊
82
2024-06-27 17:10:18
栏目: 编程语言

是的,replaceAll 方法支持链式调用。可以连续调用多个 replaceAll 方法来对字符串进行多次替换操作。例如:

String str = "Hello world!";
String newStr = str.replaceAll("Hello", "Hi").replaceAll("world", "Universe");
System.out.println(newStr); // Output: Hi Universe!

0