繁体   English   中英

解释用空格分割的输出

[英]Interpreting the output of splitting with white spaces

我们如何解释以下执行的输出

String s="   "  //3 white spaces
String arr[]=s.split(" ")   // output arr has no elements, same is the case on using \\s+ as the delimiter.

如果我们在 python 中做同样的事情,操作是['' ,'' ,'']这是可以理解的。

java如何拆分上述内容,为什么 arr 中没有元素?

根据文档,“因此,结果数组中不包含尾随空字符串。”

如果您想要尾随空字符串s.split(" ", -1)您可能更喜欢使用s.split(" ", -1)

链接: https : //docs.oracle.com/javase/7/docs/api/java/lang/String.html#split(java.lang.String)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM