aravinth aravinth - 2 years ago 117
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?

Answer Source

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

array[array.length-1] = lastElement;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download