首页 > 编程语言 > 详细

JAVA数组遍历的3种方法——2020美团面试问题一

时间:2020-06-17 12:38:34      阅读:54      评论:0      收藏:0      [点我收藏+]

参考:https://www.cnblogs.com/baiaixing/p/11369514.html

 

  1. for 循环
  2. foreach

如:

1 public class DemoForEach {
2     public static void main(String[] args) {
3         int[] a={0,1,2,3,4,5};
4         for(int x:a){
5             System.out.println(x);
6         }
7     }

  3. jdk自带方法:java.util.Arrays.toString()

import java.util.Arrays;

public class Solution {
    public static void main(String[] args) {
        int[] a = {9, 23, 43, 2, 7, 9};

        System.out.println(Arrays.toString(a));

    }

}

 

JAVA数组遍历的3种方法——2020美团面试问题一

原文:https://www.cnblogs.com/ruiliu21/p/13151655.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!