A bug in the implementation of the RemoveAt() method of the Array class

image

But it seems like there’s a tiny little bug in the implementation of the RemoveAt() method. I believe the for-loop condition should be i < count - 1 and not i < count.
This scenario will lead to an IndexOutOfRange exception:

Array array = new Array(3);
array.Insert(10);
array.Insert(20);
array.Insert(30);
array.RemoveAt(1);
array.Print();

1 Like

Actually you’re right, I was facing OutOfRange exception, even my solution (with C#), was the same as in the course, so a change with your sugestion and it pass the test.
Thank you!

@moshhamedani hey mosh and how are you and thanks for courses and I am progressing, I want to ask you about the data structure course , in the Arrays , how do u connect public static void main(){ Array numbers = new Array(length:3) } from where you declared from other functions Array.java from the lession 4 to lession 5 ? When u set initation private int[] length? And if i declare length:3 that colon : gives me an error!

Any help will do

Thanks!

Jason Ma

Thank you for responding chung ,

One question is do i need to tie main.java and array.java together in way so array can run main method or makes sense for me to put main method to run to the program in one file when put public static vois main (string [] args ) into the array.java api

Thanks again happy new year

And also on top of that hwo do u define insert ? When state the array when u define numbers.insert(5) say the index is 4 . The insert gives me error? Is it part of Java library api?

Thanks again!!!