我想通過兩個ArrayLists(稱爲sceneObjects和animationSceneObjects)進行迭代並匹配基於名稱字段的兩個ArrayList。這裏是我的代碼:使用嵌套while語句迭代兩個ArrayList - Java
Iterator<AnimationObject> itr = animationObjects.iterator();
Iterator<SceneObject> itrMain = sceneObjects.iterator();
while (itr.hasNext()) {
AnimationObject object = itr.next();
//Remove the word node from the animation object name so it matches main object name.
String tmpString = object.animationobjectName.replace("node-", "");
System.out.println("Animation Object name is" +tmpString);
while (itrMain.hasNext()) {
SceneObject objectMain = itrMain.next();
System.out.println("Scene Object name is" +objectMain.objectName);
if (tmpString.equals(objectMain.objectName)) {
System.out.println("Animation Object matched to main object array" +tmpString);
objectMain.animations = object.animationData;
objectMain.hasAnimations = true;
}
}
}
的問題是,該代碼並不如預期運行 - 這只是第一個項目在ITR迭代器itrMain迭代器的值進行比較。
任何人都可以發現我有什麼問題嗎?
謝謝。
太棒了 - 謝謝大家。 – GuybrushThreepwood