I'm not sure what the intent here is, since the code provided will not compile. However, it looks like you are adding arrays into a List. As far as I know, .equals() for arrays is the same as ==; it compares if the physical objects are the same.
So even though the arrays have the same content, the .contains() fails because the arrays are not ==.
What you would need to do is write a class that wraps around an array and override .equals() on that class to interate through the array and see if the elements of the array are equal. [ May 16, 2005: Message edited by: Joel McNary ]
Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
Joined: May 17, 2004
I did it and it still insert the duplicate data. Comments?
There's a problem in your .equals method. The List class that contains the ".contains" code does not know about the .equals(Obj) method; it only knows about .equals(Object). Thus, you have to implement .equals(Object). What you did was you overloaded the method .equals. Overloaded methods do not participate in polymorphism. However, overridden methods do. To get this to work, change your .equals method to the following:
There really is no limitation, except to say that when you override .equals(), you should also override .hashCode(), otherwise you will get unexpected results. However, in many cases object identity (==) is what we want to test, so the default implementation of .equals() and .hashCode() will do fine. Only override .equals() if it provides meaning to your code.
As far as JavaBeans go, multiple Beans can have the same settings. If your beans have a key field, you might want to override .equals() to check on the key field, but otherwise the default functionality should work fine.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus