for(String token:"==".split("=")){
System.out.println("token: "+token+" "+token.length());
}
System.out.println("###");
for(String token:" ==".split("=")){
System.out.println("token: "+token+" "+token.length());
}
System.out.println("###");
for(String token:"== ".split("=")){
System.out.println("token: "+token+" "+token.length());
}
token: 1
###
token: 0
token: 0
token: 1
resultSize--;
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()};
// Add remaining segment
if (!matchLimited || matchList.size() < limit)
matchList.add(input.subSequence(index, input.length()).toString());
// Construct result
int resultSize = matchList.size();
if (limit == 0)
while (resultSize > 0 && matchList.get(resultSize-1).equals(""))
resultSize--;
String[] result = new String[resultSize];
return matchList.subList(0, resultSize).toArray(result);
}
779

被折叠的 条评论
为什么被折叠?



