简体   繁体   English

如何将数组与新创建的List Java比较

[英]How to compare an array with an new created List java

i have a String array with information like this: 我有一个字符串数组,其信息如下:

name          street         streetnumber         City      house     flat
jetsons     jetstreet        12                  london       yes      no
jetsons     jetstreet        10                  washingston  n        y
jetsons     jetstreet        10                  washingston  n        y
jetsons     jetstreet        10                  washingston  yes      no 
ALF         alfStreet         3                  Shanghai      y        y

...and so on ...等等

now the exercise is to create an new list with unique data which is analyzed. 现在的工作是创建一个包含唯一数据的新列表,并对其进行分析。

livingDataArray analyzedDataList livingDataArray分析数据列表

while(livingDataArray=reader.readLine() != null){
        street = livingDataArray[1];
        streetNumber = livinDataArray[2];
        city = livingDataArray[3;]

    if(analyzedDataList.isEmpty()) {
        createNewEntry in analyzedDataList(); // that line is fine. ;)
    } else {
        int analyzedDataSize = analyzedData.size();
        for (int i = 0; i <= analyzedDataSize; i++){

                  if(analyzedData.get(i)[1] == street && 
                    analyzedData.get(i)[2] == streetNumber &&
                    analyzedData.get(i)[3] == city ) {

                   categorize(); // this line is fine also
                   addToAnalyzedData();
                  break;
                  } else if (!(analyzedData.get(i)[1] == street && 
                    analyzedData.get(i)[2] == streetNumber &&
                    analyzedData.get(i)[3] == city) && (i+1 ==
                    livingData.size())) {

                             categorize();
                             addToAnalyzedData();
                             break;
                    }


             }
        }
}

My question is that efficient enough to use it for really big data? 我的问题是,它足够有效地用于真正的大数据吗? Like 100.000 rows and more? 像100.000行或更多? Because I'm not about the if else statements. 因为我不是关于if else语句。 Could anybody help me? 有人可以帮我吗?

String comparison works via equals , not == ( How do I compare strings in Java? ). String比较通过equals而不是==我如何在Java中比较字符串? )。 Next point: This looks like the implementation in java of a plain SELECT DISTINCT * FROM someWhere -statement in SQL. 下一步:看起来像普通SELECT DISTINCT * FROM someWhere -SQL中Java声明的Java实现。 So why not simply outsource the code to a database? 那么,为什么不简单地将代码外包给数据库呢? If that's not possible, a Set would be most likely the most efficient collection. 如果这不可能,那么Set将最有可能是最有效的集合。 Though i'd recommend SQL to improve performance a lot and save resources on your local PC. 尽管我建议使用SQL来提高性能,并节省本地PC上的资源。 One final note: Modifying data in a loop over the same data like here: 最后一点:在相同数据上循环修改数据,如下所示:

int analyzedDataSize = analyzedData.size();
for (int i = 0; i <= analyzedDataSize; i++){
    ...
        addToAnalyzedData();

is extremely prone to bugs/exceptions. 非常容易出现错误/异常。 For eg you're retrieving and modifying a collection in the loop mentioned above, without updating the size of the collection. 例如,您要在上述循环中检索和修改集合,而无需更新集合的大小。 In this example, this behavior won't do any damage, but you should handle this rather carefully. 在此示例中,此行为不会造成任何损害,但您应谨慎处理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM