我试图遍历Java中的两个数组,同时还要检查值是否相等

我试图遍历许多数组,一次两次。它们每个包含上万个条目,包括源。在这种情况下,我试图将每个单词分配给名词,动词,形容词或副词。


我似乎想不出一种方法来比较两个数组,而不必编写if语句数千次。


我在Google和SO上搜索了类似的问题。我找不到任何能使我前进的东西。


package wcs;


import dictionaryReader.dicReader;

import sourceReader.sourceReader;


public class Assigner {

    private static String source[], snArray[], svArray[], sadvArray[], sadjArray[];

    private static String nArray[], vArray[], advArray[], adjArray[];

    private static boolean finished = false;


public static void sourceAssign() {

    sourceReader srcRead = new sourceReader();

    //dicReader dic = new dicReader();

    String[] nArray = dicReader.getnArray(), vArray = dicReader.getvArray(), advArray = dicReader.getAdvArray(),

            adjArray = dicReader.getAdjArray();


    String source[] = srcRead.getSource();


    // Noun Store

    for (int i = 0; i < source.length; i++) {

        if (source[i] == dicReader.getnArray()[i]) {

            source[i] = dicReader.getnArray()[i];               

        }else{


        }

    }

    // Verb Store


    // Adverb Store


    // Adjective Store

}

}


紫衣仙女
浏览 185回答 1
1回答

Helenr

基本上,这是一种获取两个项目均列表的更简单方法 Lists// construct a list of item for first list&nbsp; &nbsp; &nbsp; &nbsp; List<String> firstList = new ArrayList<>(Arrays.asList(new String[0])); // add items&nbsp; &nbsp; &nbsp; &nbsp; //this function will only keep items in `firstList` if the value is in both lists&nbsp; &nbsp; &nbsp; &nbsp; firstList.retainAll(Arrays.asList(new String[0]));&nbsp; &nbsp; &nbsp; &nbsp; // iterate to do your work&nbsp; &nbsp; &nbsp; &nbsp; for(String val:firstList) {&nbsp; &nbsp; &nbsp; &nbsp; }
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java