一维数组遍历
对一维数组的 元素遍历输出。
示例一:
基本for循环。
public class Demo { public static void main(String[] args) { int[] arr = { 11, 22, 33 }; for (int i = 0; i < arr.length; i++) { System.out.println(arr[i]); } } } |
运行结果:
11
22
33
示例二:
增强for循环。
public class Demo { public static void main(String[] args) { int[] arr = { 11, 22, 33 }; for (int ar : arr) { System.out.println(ar); } } } |
运行结果:
11
22
33
示例三:
IntStream流。
import java.util.Arrays; public class Demo { public static void main(String[] args) { int[] arr = { 11, 22, 33 }; Arrays.stream(arr).forEach(System.out::println); } } 一维数组遍历 对一维数组的 元素遍历输出。 示例一: 基本for循环。
运行结果: 11 22 33 示例二: 增强for循环。
运行结果: 11 22 33 示例三: IntStream流。
|