Java 中的每个循环的原始数组如何与 new 一起使用? [英] How does primitive array work with new for each loop in Java?

查看:30
本文介绍了Java 中的每个循环的原始数组如何与 new 一起使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道 new for 每个循环适用于 Iterable 和数组,但我不知道使用数组时的幕后情况.

I understand that new for each loop works with Iterable and arrays, but I don't know what goes behind the scenes when working with arrays.

谁能帮我理解一下?提前致谢.

Can anyone help me understand this? Thanks in advance.

int[] number = new int[10];

for(int i: number) {

}

推荐答案

循环相当于:

for(int j = 0; j < number.length; j++) {
  int i = number[j];
  ...
}

其中 j 是内部生成的引用,与普通用户标识符不冲突.

where j is an internally generated reference that does not conflict with normal user identifiers.

这篇关于Java 中的每个循环的原始数组如何与 new 一起使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆