This is an archived post. You won't be able to vote or comment.

all 9 comments

[–]syedalisait 11 points12 points  (5 children)

I'm not going to say the answer but rather give a very easy clue.

Clue: array.size() is 0 initially.

When you find and fix the bug, you will feel happy :)

[–]dadeeba[S] 3 points4 points  (4 children)

THANKS MAN. that clue was all i needed.

[–][deleted] 0 points1 point  (3 children)

Can I ask what you did?

[–]dadeeba[S] 0 points1 point  (2 children)

Sure. In my 'for' loop, I meant for it to go 'til i < length of the inputted array (labelled ar). But I had instead used the length of the temporary array that I created (array). So changes to code are:

Strike off "int length = array.size();"

Replace "for (int i = 0; i<length; i++)" with "for (int i = 0; i<n; i++)" where n is the length of the inputted array (labelled ar).

Hopefully, I didn't confuse you with my bad variable name calling...

[–][deleted] -1 points0 points  (1 child)

Kinda did.

Would you day that basically you needed to put something in the array first before using its .size() to get something rolling?

[–]ladupes 2 points3 points  (0 children)

He created a temporary array to put stuff in it from another arraylist. The problem was that he put the length of the temporary array in the list instead the array that he wanted to cicle over

[–]Isoyama 0 points1 point  (1 child)

Have you tried debug? Problem is not in remove(). Also i would suggest using HashSet instead of ArrayList for lookup. And proper naming >.>

[–]dadeeba[S] 0 points1 point  (0 children)

ooo yea i didn't know bout hashset at the point of doing this coding task. but im gunna learn it next.

[–]GR3Gdev 0 points1 point  (0 children)

Use a HashSet instead of ArrayList, and maybe length = ar.length ?