[英]last index of an element in an array in java using recursion. However i have doubts shouldnt this code return the first index?
不需要复杂的公式。 您可以使用简单的命令获取最后一个索引:
//Suppose you have any array named arr
int lastIndex = arr.length-1;
//you need -1 because length will start with 1, but index starts with 0.
至少如果我正确理解你的问题。 如果您想要第一个索引,则该索引始终为 0,除非您的数组为空。 这对你有帮助吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.