for i in range(1, 11):
print(i)
for (int i = 1; i < 11; i++) {
System.out.println(i);
}
항상 기본 for문만 사용했었는데 Stream으로 간단하게 한 줄로 가능하다는 것을 알았다...!
import java.util.stream.IntStream;
public class StreamExample {
public static void main(String[] args) {
IntStream.range(1, 11).forEach(System.out::println); // 메서드 레퍼런스 방식
IntStream.range(1, 11).forEach(x->System.out.println(x)); // 람다식
}
}
람다식도 익숙하지 않아서 아직 잘 못 쓰는데 메서드 레퍼런스 방식은 진짜 모르겠다,,,,😀 간결한 건 좋은데 직관적이지 않아서 더 어렵게 느껴지는 것 같다.