为什么“分裂"在空字符串上返回非空数组? [英] Why does "split" on an empty string return a non-empty array?
本文介绍了为什么“分裂"在空字符串上返回非空数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
拆分空字符串返回大小为 1 的数组:
Split on an empty string returns an array of size 1 :
scala> "".split(',')
res1: Array[String] = Array("")
考虑这会返回空数组:
scala> ",,,,".split(',')
res2: Array[String] = Array()
请解释:)
推荐答案
出于同样的原因
",test" split ','
和
",test," split ','
将返回一个大小为 2 的数组.第一个匹配项之前的所有内容都作为第一个元素返回.
will return an array of size 2. Everything before the first match is returned as the first element.
这篇关于为什么“分裂"在空字符串上返回非空数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文