我正在尝试遍历两个 ArrayList(称为 sceneObjects 和 animationSceneObjects)并根据名称字段匹配两者。这是我的代码:
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 迭代器的值进行比较。
谁能发现我做错了什么?
谢谢你。