java按照多个分隔符分割字符串

  • 分隔符中包含需要转义的特殊字符的情况
 String str = "3+2-1*5";+ - *分割因为这三个需要转义加\\
 String [] ss = str.split("\\+|\\-|\\*");
  • 分隔符中不包含需要转义的特殊字符的情况
String [] ss = str.split("[\\+\\-\\*]");
若是普通的分割符直接
 String [] ss = str.split(",||%);

猜你喜欢

转载自blog.csdn.net/m0_37556444/article/details/85044039