As the title explains the query
Can somebody please explain the behavior of following two outputs.
"".split(",").length
gives output
1
where as
",".split(",").length
gives output
0
http://docs.oracle.com/javase/6/docs/api/java/lang/String.html#split(java.lang.String,%20int)
尾随的空字符串被丢弃。
尝试:
"Foo,".split(",").length // should be 1
",foo".split(",").length // should be 1