我有两个代码tbat做同样的事情。我想知道哪一个会更快:
1
import org.apache.commons.collections.CollectionUtils;
String [] htArray = StringUtils.join (CollectionUtils.subtract (
Arrays.asList ((h + " " + t).split (" ") ),
Arrays.asList (htSelected.split (" ") ) ), " " ).split (" ");
for (String term: htArray ) {
...
}
2。
import org.apache.commons.collections.CollectionUtils;
ArrayList <String> htList = null;
try {
htList = (ArrayList <String>) CollectionUtils.subtract (
Arrays.asList ( (h + " " + t).split (" ") ),
Arrays.asList (htSelected.split (" ") ) );
} catch (Exception except) {}
if ( htList != null) {
for (String term: htList) {
...
}
}
第一个加入一个集合然后将字符串拆分成一个数组。第二个投射集合,尝试/捕获然后添加'如果'。哪一个是最优的?
答案 0 :(得分:1)
运行100次并找出