一般在项目中使用Stream的forEach取遍历集合,其效果等效于增强for循环。但是在实际应用场景中,我们需要进行普通的for循环。Stream为我们提供了什么样的API方法:
public static void main(String[] args) {
//实际对应的范围为[0,3)
IntStream.range(0, 3).forEach(i -> {
System.out.println(i);
}
);
}