Stream Gatherers | Java 22 New Feature

Поделиться
HTML-код
  • Опубликовано: 31 янв 2025

Комментарии • 5

  • @hba6018
    @hba6018 7 месяцев назад +3

    Why not List.of(...) to create a List? you are working with streams

    • @Code.Wizzard
      @Code.Wizzard  7 месяцев назад +1

      Good point. List.of() is more optimised for this scenario since it provides an immutable list. Thanks for the feedback. Although Arrays.asList() provides a fixed size list, you can still replace an element in an existing index with another one using set operation

  • @nayrban2187
    @nayrban2187 7 месяцев назад +1

    Why use generic T instead of String?

    • @PatrickUdochukwu
      @PatrickUdochukwu 7 месяцев назад +1

      To make it generic, so you can use an type of list in future

    • @Code.Wizzard
      @Code.Wizzard  7 месяцев назад +1

      Thanks Patrick for answering. Building Gatherers with generics will allow us to use the same gatherer for other types. For example we can use the same fixed window gatherer for list of Person objects instead of String.