在Java中切换字符的简单方法是什么?说我有以下内容:
String testString = "Hello World.";
// I know this doesn't work
testString = testString.replace('o', 'e');
Run Code Online (Sandbox Code Playgroud)
我想用'o'切换'e',我知道这不会有用......请让我知道我需要做什么
String testString = "Hello World.";
String replacedString = testString.replaceAll("o", "~")
.replaceAll("e","o")
.replaceAll("~","e");
Run Code Online (Sandbox Code Playgroud)
好吧,只要你的字符串没有〜