如何拆分和分隔字符串中包含的加号运算符

Dha*_*ram 1 java string split

public static void main(String[] args) {

    String s = "I+Love";
    s.split("+");
}
Run Code Online (Sandbox Code Playgroud)

这是在线程"main"中抛出异常java.util.regex.PatternSyntaxException:

man*_*uti 6

你需要逃避+特殊的角色:

s.split("\\+");  // split accepts a regular expression and `+` is a metacharacter
Run Code Online (Sandbox Code Playgroud)