Hi all I got 2 Vectors of vectors for instance I need to compare the strings inside vOrgTable_1 and vBckTable_1 and so on till i reach the end of the big vector , i made the loop to get the data for these inner vectors but i need to know how to compare the data inside , what i should do to achieve this ? i used .equals() always giving me false although they got the same strings ,
Originally posted by Mudassir Rahat: Do not compare the vectors themselves as they are different references and cannever be equal,if you want to compare the content,you will have to do it individually.Sorry there are no shortcuts.
do you mean getting the data in every index for the inner vector and compare it ?
Joined: Oct 14, 2006
Yes,As vectors can be equal only if they refer to the same object.
Originally posted by Mudassir Rahat: Yes,As vectors can be equal only if they refer to the same object.
You haven't looked at how Vector implements the equals method, have you?
Vector actually uses AbstractList's equals method (only synchronized). Here is that method:
So it returns true if all objects inside the vector are equal, and in the same order.
Consider this example:
So if equals is overridden you should be able to just use equals on the outer vectors; their elements will be compared using equals as well, etc. You could potentially have an unlimited vector depth, and just one call will be enough.