I am trying to iterate through two ArrayLists (called sceneObjects and animationSceneObjects) and match the two based on a name field. Here is my code :
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;
}
}
}
The problem is that the code isn't working as intended - it only compares the first item in the itr iterator to the values of the itrMain iterator.
Can anyone spot what I have got wrong ?
Thank you.