The answer to this has to do with how objects are stored and used in Java. For example after executing this line:
Code: Vector space = new Vector();
The "space" variable will not "store" the new vector, but is just a
reference to this newly created object. Next, for example, consider doing something like this:
Code:Vector space2 = space;
You'll
not have just created another Vector object, but have now 2 variables which refer to the same object. Makes sense?
Now the same happens in principle when you're adding a new element to this vector:
Code:space.addElement(new Space(a,b,40,40,40));
The vector will now store a reference to the new Space object.
However, because of this if you want to check if the Vector already contains this object you'll really have to check for the reference. So rewrite it like that:
Code:Space s=newSpace(a,b,40,40,40);
space.addElement(s);
...
if (space.contains(s)) ...
When you tried checking the vector in your version, you were creating another separate object (with the same values, but nevertheless with a different reference) and hence the check is always negative!
hth!