从两个不同大小/长度的数组列表中获取相同值的索引

我是 Java 新手,我想获得两个数组列表的相同值的索引,但是两个数组列表的大小/长度不同。这是工作代码:


List<String> new_valueString = new ArrayList<>();

    List<String> new_fieldsString = new ArrayList<>();

    List<String> oldValueString = new ArrayList<>();

    List<String> oldFieldsString = new ArrayList<>();


  if (new_fieldsString.size() != 0 && new_valueString.size() != 0) {

        for (int l = 0; l < new_fieldsString.size(); l++) {

                if (new_fieldsString.get(l).equalsIgnoreCase(oldFieldsString.get(l))) {

                    field_index = l;

                    if (!new_valueString.get(field_index).contains(oldValueString.get(field_index))) {

                        ifUpdated = true;

                    } else {

                        ifUpdated = false;

                    }

                }

            }


    }

我想获取 new_fieldsString 和 oldFieldsString 之间相同值的索引,并使用该索引来比较 new_valueString 和 oldValueString。


胡子哥哥
浏览 243回答 1
1回答

海绵宝宝撒

您好,您需要两个句子,一个用于第一个数组,第二个用于与短数组列表进行比较,当您发现条件为真时,不要忘记打破循环,如下所示:List<String> new_valueString = new ArrayList<>();&nbsp; &nbsp; List<String> new_fieldsString = new ArrayList<>();&nbsp; &nbsp; List<String> oldValueString = new ArrayList<>();&nbsp; &nbsp; List<String> oldFieldsString = new ArrayList<>();&nbsp; if (new_fieldsString.size() != 0 && new_valueString.size() != 0) {&nbsp; &nbsp; &nbsp; &nbsp; for (int l = 0; l < new_fieldsString.size(); l++) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;for (int m = 0; m < oldFieldsString.size(); m++) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (new_fieldsString.get(l).equalsIgnoreCase(oldFieldsString.get(m))) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (!new_valueString.get(l).contains(oldValueString.get(m))) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ifUpdated = true;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } else {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ifUpdated = false;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java