例子:爲什麼String.split以不同的方式處理字符串的開始和結束部分?
String s = ":a:b:c:";
s.split(":");
// Output: [, a, b, c]
從Java文件:
The array returned by this method contains each substring of this string that is terminated by another substring that matches the given expression or is terminated by the end of the string.
爲什麼被認爲是開始空字符串在結尾空字符串是不是? 開始的空字符串以「:」結尾,結尾的空字符串以字符串結尾終止。所以兩者都應該列出,如果他們不是?
'split'確實需要一個正則表達式..所以只是':'可能不適合您的情況 – 2013-05-06 17:05:42