[Java] for statement / extended for statement

for statement

Repeat the same process a specified number of times

	for (int i = 0 ; i < 10; i++ ) {

Execution result ➡ 0123456789

for (initialization; conditional expression; change expression) Repeat the processing in the block while the conditional expression is true

Extended for statement

Repeat as long as there are array or List elements Unlike the for statement, there are no conditional expressions or change expressions

	Integer[] array = {0,1,2,3,4,5,6,7,8,9};
	for (Integer str: array) {

Execution result ➡ 0123456789

for (Variable declaration: Array to retrieve / List name) Repeat the process in the block as long as there are elements

IntStream I received the advice that using IntStream is easy. Thank you for your advice!

IntStream.range returns a continuous value (IntStream) from the specified start value to the end value -1.

ʻIntStream.range (start value, end value) `

The processing performed by the for statement is as follows when using IntStream.

import java.util.stream.IntStream;

public static void main(String[] args) {
  IntStream.range(0, 10).forEach(System.out::print);

It's nice because you don't have to write conditional expressions for initialization and increments.

Recommended Posts

[Java] for statement / extended for statement
Java for statement
[Java] for statement, while statement
(Memo) Java for statement
[Java] Basic statement for beginners
I tried using an extended for statement in Java
[Beginner] Java variable / logical operator / extended for statement [Note 22]
How to loop Java Map (for Each / extended for statement)
[Java] Make variables in extended for statement and for Each statement immutable
For JAVA learning (2018-03-16-01)
2017 IDE for Java
Java switch statement
Java, for statement / while statement starting from beginner
Java instruction execution statement
[Java] Package for management
[Java] How to turn a two-dimensional array with an extended for statement
Use Java7 try-with-resources statement for Cursor close processing
Countermeasures for Java OutOfMemoryError
Array vs ArrayList vs HashMap Extended for Statement Race
[Java] Nowadays, the extended for statement is not exclusively for List, isn't it?
NLP for Java (NLP4J) (2)
NLP for Java (NLP4J) (1)
[Java] How to get HashMap elements by loop control using extended for statement
[Java basics] Let's make a triangle with a for statement
About for statement and if statement
Java update for Scala users
Java debug execution [for Java beginners]
[Java] Precautions for type conversion
Books used for learning Java
2018 Java Proficiency Test for Newcomers-Basics-
Java programming basics practice-for statement
Points for refactoring (if statement)
☾ Java / Iterative statement and iterative control statement
Java thread safe for you
[Java] Summary of for statements
Java programming basics practice-switch statement
Java for beginners, data hiding
[Java] Tips for writing source
Java installation location for mac
Java application for beginners: stream
Java while and for statements
Store in Java 2D map and turn with for statement
C # cheat sheet for Java engineers
New grammar for Java 12 Switch statements
[For beginners] Summary of java constructor
Utilization of Java array elements, for, length, value, and extended for statements
AWS SDK for Java 1.11.x and 2.x
Rock-paper-scissors game for beginners in Java
Java for beginners, expressions and operators 1
[For beginners] Run Selenium in Java
Hello World for ImageJ Java Plugin
[OpenCV3.2.0] Eclipse (Java) settings (for Mac)
Java for beginners, expressions and operators 2
Java learning memo (while statement, do-while statement)
[Java] Really scary switch statement story
Enable OpenCV with java8. (For myself)
Spring Framework tools for Java developer
java (use class type for field)
Build Java development environment (for Mac)
Java study # 4 (conditional branching / if statement)