Java 字符串分割方法分割2个或更多个空格
Java String split method split by 2 or more spaces
如何仅使用 java 拆分方法将字符串拆分为“2 个或更多空格”
一个例子:
"cat dog horse elephant"
将拆分为:
cat dog
horse
elephant
谢谢。
您需要使用以下 regex
拆分 String
\s{2,}
这会将字符串拆分为 2 个或更多空格
String str = "cat dog horse elephant";
String[] parts = str.split("\s{2,}");
如何仅使用 java 拆分方法将字符串拆分为“2 个或更多空格”
一个例子:
"cat dog horse elephant"
将拆分为:
cat dog
horse
elephant
谢谢。
您需要使用以下 regex
String
\s{2,}
这会将字符串拆分为 2 个或更多空格
String str = "cat dog horse elephant";
String[] parts = str.split("\s{2,}");