JAVA数组遍历的3种方法——2020美团面试问题一
参考:https://www.cnblogs.com/baiaixing/p/11369514.html
- for 循环
- 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)); } }