nameLengths = names.stream() .map(String::length) .collect(Collectors.toList()); // forEach List names = Arrays.asList("Alice", "Bob", "Charlie"); names.stream() .forEach(name -> System.out.println("Hello, " + name)); // sorted List numbers = Arrays.asList(3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5); List sortedNumbers = numbers.stream() .sorted() .collect(Collectors.toList()); // distinct List numbers = Arrays.asList(1, 2, 2, 3, 3, 3, 4, 4, 4, 4); List distinctNumbers = numbers.stream() .distinct() .collect(Collectors.toList()); // reduce 스트림의 모든 요소를 결합하거나 축소합니다 List numbers = Arrays.asList(1, 2, 3, 4, 5); int sum = numbers.stream() .reduce(0, (x, y) "> nameLengths = names.stream() .map(String::length) .collect(Collectors.toList()); // forEach List names = Arrays.asList("Alice", "Bob", "Charlie"); names.stream() .forEach(name -> System.out.println("Hello, " + name)); // sorted List numbers = Arrays.asList(3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5); List sortedNumbers = numbers.stream() .sorted() .collect(Collectors.toList()); // distinct List numbers = Arrays.asList(1, 2, 2, 3, 3, 3, 4, 4, 4, 4); List distinctNumbers = numbers.stream() .distinct() .collect(Collectors.toList()); // reduce 스트림의 모든 요소를 결합하거나 축소합니다 List numbers = Arrays.asList(1, 2, 3, 4, 5); int sum = numbers.stream() .reduce(0, (x, y) "> nameLengths = names.stream() .map(String::length) .collect(Collectors.toList()); // forEach List names = Arrays.asList("Alice", "Bob", "Charlie"); names.stream() .forEach(name -> System.out.println("Hello, " + name)); // sorted List numbers = Arrays.asList(3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5); List sortedNumbers = numbers.stream() .sorted() .collect(Collectors.toList()); // distinct List numbers = Arrays.asList(1, 2, 2, 3, 3, 3, 4, 4, 4, 4); List distinctNumbers = numbers.stream() .distinct() .collect(Collectors.toList()); // reduce 스트림의 모든 요소를 결합하거나 축소합니다 List numbers = Arrays.asList(1, 2, 3, 4, 5); int sum = numbers.stream() .reduce(0, (x, y) ">

// filter
List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5, 6);
List<Integer> evenNumbers = numbers.stream()
    .filter(n -> n % 2 == 0)
    .collect(Collectors.toList());

// map
List<String> names = Arrays.asList("Alice", "Bob", "Charlie");
List<Integer> nameLengths = names.stream()
    .map(String::length)
    .collect(Collectors.toList());

// forEach
List<String> names = Arrays.asList("Alice", "Bob", "Charlie");
names.stream()
    .forEach(name -> System.out.println("Hello, " + name));

// sorted
List<Integer> numbers = Arrays.asList(3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5);
List<Integer> sortedNumbers = numbers.stream()
    .sorted()
    .collect(Collectors.toList());

// distinct
List<Integer> numbers = Arrays.asList(1, 2, 2, 3, 3, 3, 4, 4, 4, 4);
List<Integer> distinctNumbers = numbers.stream()
    .distinct()
    .collect(Collectors.toList());

// reduce 스트림의 모든 요소를 결합하거나 축소합니다
List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5);
int sum = numbers.stream()
    .reduce(0, (x, y) -> x + y);

// 스트림의 요소를 컬렉션으로 수집합니다.
List<String> names = Arrays.asList("Alice", "Bob", "Charlie");
Set<String> nameSet = names.stream()
    .collect(Collectors.toSet());

// findFirst or findAny
List<String> names = Arrays.asList("Alice", "Bob", "Charlie");
Optional<String> firstName = names.stream()
    .findFirst();

// mapToInt (maptToLong 또한 동일)
List<String> numbersAsString = Arrays.asList("1", "2", "3", "4", "5");

        // 문자열을 정수로 매핑하고 IntStream으로 반환
        IntStream intStream = numbersAsString.stream()
                .mapToInt(Integer::parseInt);

        // 매핑된 정수를 사용하여 연산 수행
        int sum = intStream.sum();
        int max = intStream.max().orElse(0);

        System.out.println("Sum: " + sum);
        System.out.println("Max: " + max);

// flatMap
List<List<Integer>> listOfLists = Arrays.asList(
    Arrays.asList(1, 2, 3),
    Arrays.asList(4, 5, 6),
    Arrays.asList(7, 8, 9)
);

List<Integer> flattenedList = listOfLists.stream()
    .flatMap(List::stream)
    .collect(Collectors.toList());

List<Integer> flattenedList = listOfLists.stream()
    .flatMap(innerList -> innerList.stream()) // 람다 표현식으로 변경
    .collect(Collectors.toList());

[
  [1, 2, 3],
  [4, 5, 6],
  [7, 8, 9]
]
--> 
[1, 2, 3, 4, 5, 6, 7, 8, 9]