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.
以上兩種方法都可以實現字符串的批量替換,具體選擇哪種方法取決于具體的需求和使用場景。