1
所以我正在编写一个解析CSV的程序。我使用split方法将值分隔成一个字符串数组,但我读过一些文章,它使用substring和indexOf更快。我基本上写了我会用这两种方法做什么,似乎分裂会更好。有人可以解释这是如何更好,或者如果我没有正确使用这些方法?这是我写的:拆分方法vs子串和索引
int indexOne = 0, indexTwo;
for (int i = 0; i < 4; i++) //there's four diff values in one line
{
if (line.indexOf(",", indexOne) != -1)
{
indexTwo = line.indexOf(",", indexOne);
lineArr[i] = line.substring(indexOne, indexTwo);
indexOne = indexTwo+1;
}
}
你可能会链接一些这些文章? –
考虑使用lodash或下划线或类似的东西来处理这样的事情。 – Michael
@AustinD这里有一个链接http://demeranville.com/battle-of-the-tokenizers-delimited-text-parser-performance/有人把它放在stackexchange的评论这里是该线程http://programmers.stackexchange.com/questions/221997 /最快路径分割-a-delimited-string-in-java – trevalexandro