简体   繁体   English

从具有两个不同大小/长度的两个arraylist获取相同值的索引

[英]Get index of the same value from two arraylist with two different sizes/length

I am new to Java and I want to get the index of same value of two arraylist however the two arraylist do NOT have the same size/length. 我是Java新手,我想获取两个arraylist值相同的索引,但是两个arraylist的大小/长度不同。 This is the working code: 这是工作代码:

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;
                    }
                }
            }

    }

I want to get the index of the same value between new_fieldsString and oldFieldsString and use that index to compare the new_valueString and oldValueString. 我想获取new_fieldsString和oldFieldsString之间相同值的索引,并使用该索引来比较new_valueString和oldValueString。

Hello You need a two for sentences one for your first array and second to compare with the short arraylist and when you find your condition true not forget break the loop, some like this: 您好,您需要两个句子的第一个数组,第二个数组与短数组列表进行比较,当您发现条件为真时,别忘了打破循环,像这样:

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++) {
           for (int m = 0; m < oldFieldsString.size(); m++) {
                if (new_fieldsString.get(l).equalsIgnoreCase(oldFieldsString.get(m))) {
                    if (!new_valueString.get(l).contains(oldValueString.get(m))) {
                        ifUpdated = true;
                    } else {
                        ifUpdated = false;
                    }
                    break;
                }
            }
        }
    }

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

相关问题 映射两个具有不同大小的ArrayList - Map two ArrayList with different sizes 在Java中读取两个不同的arrayList值,并将其添加到同一数组Object - Read two different arrayList value in java and add it to a same array Object 如果我从第一个ArrayList中删除了一个值,如何在两个ArrayList上获得相同的位置 - How to get the same position on two ArrayListif I have removed a value from the first ArrayList 在Java中,如何同时增加两个不同大小的数组(列表)的索引? - In java, how do I increase the index of two array(list)s of different sizes at the same time? 如何从Java / Android中的两个ArrayList获取不同的值? - How to get different values from two ArrayList in Java/Android? 两个字符串中长度为2(在相同索引处)的匹配子序列 - Matching subsequence of length 2 (at same index) in two strings 具有两个值相同但存储桶索引不同的键对象的哈希图 - Hashmap with two key object having same value but different bucket index 为什么我从arrayList的不同对象中获得相同的值? - Why do I get the same value from different objects an an arrayList? 从ArrayList中删除两个受索引影响的元素 - Removing two elements from ArrayList affected by index 如何从同一行显示的Excel文件中显示两个不同大小的数组以输出PDF? - How to display two arrays of different sizes from an Excel file displayed on same line for PDF output?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM