Java中forEach, 用来遍历数组
生活随笔
收集整理的這篇文章主要介紹了
Java中forEach, 用来遍历数组
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
這里的for是Java中forEach, 用來遍歷數組的。
for(int i : d) 就是遍歷int型數組d的 每一次訪問數組d的時候讀取的數據放入int型的i中。
和for(int i=0;i<d.length();i++)是一樣的,但是forEach的可用場合較多。
public class e1 {
public static void main(String[] args){
int[]d=new int[] {1,2,3,4,64,1234,3124,657,22};
System.out.println("d.length="+d.length);
for(int i : d){
System.out.println(i);
}
for(int i : d) 就是遍歷int型數組d的 每一次訪問數組d的時候讀取的數據放入int型的i中。
和for(int i=0;i<d.length();i++)是一樣的,但是forEach的可用場合較多。
public class e1 {
public static void main(String[] args){
int[]d=new int[] {1,2,3,4,64,1234,3124,657,22};
System.out.println("d.length="+d.length);
for(int i : d){
System.out.println(i);
}
轉載于:https://www.cnblogs.com/AceIsSunshineRain/p/5095212.html
總結
以上是生活随笔為你收集整理的Java中forEach, 用来遍历数组的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 中银都市卡的年费是多少?免年费政策怎么样
- 下一篇: Java反射机制的使用方法