How I can index the array starting from 1 instead of zero?

后端 未结 5 1007
滥情空心
滥情空心 2020-12-10 09:46
for (int i = 0; i < reports.length; i++) {

  Products[] products = reports[i].getDecisions;

  for (int j = 0; j < products.length; j++) {

  }
}
5条回答
  •  抹茶落季
    2020-12-10 10:25

    Java arrays are always 0-based. You can't change that behavior. You can fill or use it from another index, but you can't change the base index.

    It's defined in JLS §10.4, if you are interested in it.

    A component of an array is accessed by an array access expression (§15.13) that consists of an expression whose value is an array reference followed by an indexing expression enclosed by [ and ], as in A[i].

    All arrays are 0-origin. An array with length n can be indexed by the integers 0 to n-1.

提交回复
热议问题