-3

我有 2 个代码 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) {
        ...
    }
}

第一个加入一个集合,然后将字符串拆分为一个数组。第二个转换集合,尝试/捕获然后添加一个'if'。哪一个是最优的?

4

1 回答 1

1

运行它 100 次并弄清楚

于 2012-04-25T22:32:45.580 回答