aravinth aravinth - 9 months ago 47
Java Question

How to implement negative indexes in java?

In Python, you are allowed to use negative array indices to count starting from the right side of an array. For example, array[-1] is last element and array[-2] is the second last element in the array. How would you do this in Java?


Java does not support negative indexes, to access the last cell, you should use

array[array.length-1] = lastElement;