There are three kinds of actuaries: those who can count, and those who can't.
[OCP 17 book] | [OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
[OCP 17 book] | [OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Jeanne Boyarsky wrote:Piet,
addAll() would allow duplicates in the list. If this were a set, I see how that would work. I'm puzzled for a list.
Jeanne Boyarsky wrote:
This code adds the item to listThree unconditionally. What changes is that it inserts it at index 0 or index 1 depending on whether it is in listOne. That's not what you want. Try creating an if statement around the add call.
[OCP 17 book] | [OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Raymond Gillespie wrote:They are String objects.
Raymond Gillespie wrote:
I tried this and got the same outcome. It still adds every object from list two into list three
[OCP 17 book] | [OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Raymond Gillespie wrote:They are String objects.
Raymond Gillespie wrote:It is an items object. What I mean is that Strings are in the objects. I do have an equals() method in the items class so perhaps that is the issue.
Paweł Baczyński wrote:And hashCode(), of course.
Henry Wong wrote:
Raymond Gillespie wrote:It is an items object. What I mean is that Strings are in the objects. I do have an equals() method in the items class so perhaps that is the issue.
Whether it is an issue or not would depend... well, perhaps you can show us the implementation of the equals() method from the Items class.
Henry
Jeanne Boyarsky wrote:Piet,
addAll() would allow duplicates in the list. If this were a set, I see how that would work. I'm puzzled for a list.
There are three kinds of actuaries: those who can count, and those who can't.
Raymond Gillespie wrote:This is the equals() method. I didn't write it. I just used the generate feature in Eclipse.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
I'm gonna teach you a lesson! Start by looking at this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
|