如何在包含空格的java中拆分字符串?

String test = "1\t0.000000000\t192.168.0.24\t\t10.0.0.5\t\t98\t84\t\t\t\t\t\t\t\t1";


输出数组列表应类似于:

["1"," ","0.000000000", " ","192.168.0.24", " ", " ","10.0.0.5"...(well you get me)]

最佳答案

试试这个。

      String text = "1\t0.000000000\t192.168.0.24\t\t10.0.0.5\t\t98\t84\t\t\t\t\t\t\t\t1";

      String[] result = text.replaceAll("\t", "\t \t").split("(\t)+");

10-05 18:48