May 31, 2019

How to Check if Index Is in Range [0, n)

In order to check whether or not an index is in range [0, n) we can rely on a “if” statement, as below: if (index = n) { … } But, Java 9 comes with the method bjects.checkIndex()¬†that checks if the given index is in range [0, n). This method