[英]Interpreting the output of splitting with white spaces
How do we interpret the output of the flollowing execution我们如何解释以下执行的输出
String s=" " //3 white spaces
String arr[]=s.split(" ") // output arr has no elements, same is the case on using \\s+ as the delimiter.
If we do the same in python, the op is ['' ,'' ,'']
which is understood.如果我们在 python 中做同样的事情,操作是
['' ,'' ,'']
这是可以理解的。
How does java split the above and why is there no element in arr ? java如何拆分上述内容,为什么 arr 中没有元素?
Per the documentation, "Trailing empty strings are therefore not included in the resulting array."根据文档,“因此,结果数组中不包含尾随空字符串。”
You may prefer to use s.split(" ", -1)
if you want trailing empty strings.如果您想要尾随空字符串
s.split(" ", -1)
您可能更喜欢使用s.split(" ", -1)
。
Link: https://docs.oracle.com/javase/7/docs/api/java/lang/String.html#split(java.lang.String)链接: https : //docs.oracle.com/javase/7/docs/api/java/lang/String.html#split(java.lang.String)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.