Got error in when removeAt() function in java

Hello guys, I got error when Implement removeAt() function in arryas (ds&algo part1).
I coded same as mosh how taught in video. But it got error like (index 6 out of bounds for length 6)
Please give any solution for this.

ngth 6)


are you sure this is the code given in the course?
Try changing the condition in the for loop to count-1

i i+1 count Note
2 3 6 Item at index 3 crushes item at index 2
3 4 6 Item at index 4 crushes item at index 3
4 5 6 Item at index 5 crushes item at index 4. 5 is the greatest valid index in your table
5 6 6 At this point i+1 is out of bound. Hence the exception
6 7 6 Loop would not be executed because 6 is not strictly less than 6


1 Like

Previously answered. Please search the forums before asking questions.

1 Like

Yep, this is very frustrating.

Yes, this code was given my mosh also taught this code in his tutorial. But first time it was worked. Then I don’t know what happened it’s not working properly. I know there is mistake in loop condition because it was out of bounds error. But I am beginner so it’s hard to me for debug this error.

Hell yeah, it’s working dude thanks for your help uniqueNospaceShort your are saviour.