String.split(“.”) is not splitting my long String

后端 未结 2 1415
感动是毒
感动是毒 2021-01-19 10:28

I\'m doing the following:

String test = \"this is a. example\";
String[] test2 = test.split(\".\");

the problem: test2 has no

2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-19 10:51

    The dot . is special regex character. It means match any. You need to escape the character, which in Java is done with \\.

    Once it is escaped, it won't be treated as special and will be matched just like any other character.

    So String[] test2 = test.split("\\."); should do the trick nicely!

提交回复
热议问题