Carey Brown wrote:A personal preference:
I can see throwing an exception if null is passed in, however, I'd rather have a boolean returned as to whether the add was successful or not.
Piet Souris wrote:As an aside: the singular form of media is medium (well, in Holland anyway). But admitted: many people talk about 'medias' as plural.
are you being taught about the 'equals' method? Campbell and Liutauras mentioned it, but it would simplify your code.
Norm Radder wrote:Did you see my earlier post?
If the object is to NOT add a duplicate, what is the purpose of the duplicate variable and remove method?
If the list contains an item that is the same as the one to be added, why not just exit the method when the match is found and NOT add the new item?
Norm Radder wrote:
line 36 is failing
I see line 36 to be: @Test
How does that line fail?
Is there an error message?
Norm Radder wrote:
The 3rd test is failing.
What line(s) is the 3rd test?
How can anyone compile and execute the code for testing? Missing imports and class definitions
Norm Radder wrote:Did you look at the API doc for the ArrayList class to see if any of its methods would be useful?
Campbell Ritchie wrote:Welcome to the Ranch
Please explain what that code is supposed to do, and whether there is supposed to be any relationship to the thread title. I can see nothing in there that would prevent duplication. Please remove the loop, because it doesn't do anything. What you are doing is iterating something, then testing whether its title equals itself, then getting a title and not doing anything with it. So the loop takes time to achieve nothing.
Then you are adding the object to the Iterable, unless it is null.
Don't have a field and a parameter with the same name; that is a good source of confusion. It is maybe better to throw a null pointer exception f you are presented with a null, or better still condense the method toThat will throw the exception for you if you pass null. But I can't say more until I know what you mean about duplicates.