# Got error in when removeAt() function in java

**URL:** <https://forum.codewithmosh.com/t/got-error-in-when-removeat-function-in-java/16066>\
**Category:** Data Structures\
**Created:** [October 26, 2022, 11:31am UTC](https://forum.codewithmosh.com/t/got-error-in-when-removeat-function-in-java/16066 "2022-10-26T11:31:41Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![jmrunkle](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/jmrunkle/32/3765_2.png) [@jmrunkle](https://forum.codewithmosh.com/u/jmrunkle)\
**Post date:** [October 27, 2022, 2:11am UTC](https://forum.codewithmosh.com/t/got-error-in-when-removeat-function-in-java/16066/3 "2022-10-27T02:11:06Z")

</div>

> [@Data structure removeat](https://forum.codewithmosh.com/t/data-structure-removeat/13696/4):
>
> There are only two hard things in Computer Science: cache invalidation, naming things, and off-by-one errors. – Computer Scientists Just got access to the course (decided to try the annual subscription at a discount) and you are correct. Mosh’s solution has an off-by-one error which is very common in programming. Instead of using i \< count Mosh should have used i \< count - 1 because you want to stop one before the last item. public void removeAt(int index) { if (i \< 0 || i \>= count) { …

Previously answered. Please search the forums before asking questions.

---

_[View the full topic](https://forum.codewithmosh.com/t/got-error-in-when-removeat-function-in-java/16066)._
