main 실행문
import java.util.stream.IntStream;
class Main {
public static void main(String[] args) {
new ver1().run();
System.out.printf("\n");
new ver2().run();
System.out.printf("\n");
new ver3().run();
System.out.printf("\n");
new ver4().run();
System.out.printf("\n");
new ver5().run();
}
}
for문 방식
class ver1{
public void run(){
for (int i = 1; i <= 10; i++) {
System.out.printf("%d",i);
}
}
}
Stream 기본
class ver2 {
public void run() {
IntStream.range(1, 11)
.forEach(e -> {
System.out.printf("%d", e);
});
}
}
Stream 방식1 - foreach
class ver3 {
public void run() {
IntStream.rangeClosed(1, 10)
.forEach(e -> {
System.out.printf("%d", e);
});
}
}
Stream 방식2 - 1줄이하의 단순구성 {}소괄호 생략가능
class ver4
public void run(){
IntStream.rangeClosed(1,10)
.forEach( e -> System.out.printf("%d",e) );
}
Stream 방식3 - 축약
class ver5 {
public void run(){
IntStream.rangeClosed(1,10)
.forEach(System.out::println);
}
}