[英]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.