var A="1,2,3";
A.split(',')=[1,2,3];
A.split(',').length=3;
var B="";
A.split(',')=[""];
A.split(',').length=1;
如何使空字符串转化为长度为0的数组
var A="1,2,3";
A.split(',')=[1,2,3];
A.split(',').length=3;
var B="";
A.split(',')=[""];
A.split(',').length=1;
如何使空字符串转化为长度为0的数组
public String[] split(CharSequence input, int limit) {
int index = 0;
boolean matchLimited = limit > 0;
ArrayList<String> matchList = new ArrayList<String>();
Matcher m = matcher(input);
// Add segments before each match found
while(m.find()) {
if (!matchLimited || matchList.size() < limit - 1) {
String match = input.subSequence(index, m.start()).toString();
matchList.add(match);
index = m.end();
} else if (matchList.size() == limit - 1) { // last one
String match = input.subSequence(index,
input.length()).toString();
matchList.add(match);
index = m.end();
}
}
// If no match was found, return this
if (index == 0)
return new String[] {input.toString()};
split方法的源码。因为正则匹配不到字符。。。就直接返回一个数组 ,数组中包着 空字符串 所以他的长度是1
其实你可以对A进行判断是否是空字符串,空字符串就直接赋值空数组
13 回答13.1k 阅读
7 回答2.3k 阅读
3 回答1.4k 阅读✓ 已解决
6 回答1.4k 阅读✓ 已解决
2 回答1.5k 阅读✓ 已解决
3 回答1.5k 阅读✓ 已解决
6 回答1.2k 阅读