Java字符串批量替换的方法有多种,下面列举了两种常用的方法:
String str = "This is a test string.";
String replacedStr = str.replace("is", "was");
System.out.println(replacedStr);
// Output: Thwas was a test string.
String str = "This is a test string.";
String replacedStr = str.replaceAll("is", "was");
System.out.println(replacedStr);
// Output: Thwas was a test string.
以上两种方法都可以实现字符串的批量替换,具体选择哪种方法取决于具体的需求和使用场景。