I have a loop, which creates objects. The first Object 'myObject' gets Strings from an other class (the class stores strings in an array. I can access the strings through an hashmap). The Object myOtherObject stores myOject. I want to test whether the object attributes are already present in the object before after every loop continuous. If that's the case I don't want to create a new Object of the class MyClass and continue the loop.
MyClass myObject = new MyClass(mysecObject.get("Value"));
MyOtherClass myOtherObject = new MyOtherClass(myObject);
It is very difficult to show you the code of the loop because there are a lot of own methods and objects.
while(true)
{
someClass l = someOtherObject.myMethod();
if (l == null)
{
break;
}
MyClass myObject = new MyClass(l.get("Value"));
MyOtherClass myOtherObject = new MyOtherClass(myObject);
...adding myOtherObject to an HashMap
}
Edit: I made some logical mistakes and I apologize for asking a question before I really thought about it. As it has already been mentioned in the comments I have to create the objects befor I can check if the instances are equal or not (of course it works that way). I solved my problem and want to share it with you. I created an HashSet which automatically checks for duplicate entries and put the objects, which are created in the loop, in the HashSet. How simple is that? Thank you guys for your help and understanding. Have a nice day!