我试图遍历许多数组,一次两次。它们每个包含上万个条目,包括源。在这种情况下,我试图将每个单词分配给名词,动词,形容词或副词。我似乎想不出一种方法来比较两个数组,而不必编写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}}
1 回答
Helenr
TA贡献1780条经验 获得超4个赞
基本上,这是一种获取两个项目均列表的更简单方法 Lists
// construct a list of item for first list
List<String> firstList = new ArrayList<>(Arrays.asList(new String[0])); // add items
//this function will only keep items in `firstList` if the value is in both lists
firstList.retainAll(Arrays.asList(new String[0]));
// iterate to do your work
for(String val:firstList) {
}
添加回答
举报
0/150
提交
取消