Java Streams | MapToInt & Sum Example | Tech Primers

แชร์
ฝัง
  • เผยแพร่เมื่อ 6 พ.ย. 2024

ความคิดเห็น • 5

  • @vpezzano
    @vpezzano 6 ปีที่แล้ว

    Hi, thanks for this video. A small clarification. You say (minute 02:56) that map didn't have any terminal operations. But, as far as I can see, map has terminal operations, like for example count. I guess it can't have sum just because with map you can map from a generic type T to a generic type S, and it's not guaranteed that the sum operation is defined in the domain of T objects; while, if you use mapToInt (and similar) you have this operation for sure.

  • @GiriAlkondanSubbiah
    @GiriAlkondanSubbiah 6 ปีที่แล้ว +1

    Hi, Nice video.. How can we use RegEx with Map? I have a list of string with Pattern. I would like to do a exact match for a word in that list of string and return true if so. I tried as below. Please suggest if there is a better way.
    strList.stream().map(s -> regexMatcher(regex, s)).collect(Collectors.toSet()).contains("searchWord")

    • @TechPrimers
      @TechPrimers  6 ปีที่แล้ว +1

      if you just need exact match of the words you dont even need to iterate whole list. you can do it more efficiently with filters and optional
      Optional optional = strList.stream().filter(name -> name.equals("searchWord").findFirst();
      optional.isPresent() -> returns true or false.

  • @nehajain216
    @nehajain216 6 ปีที่แล้ว +1

    Thanks. Simple and to he point explanation.

  • @АлексейДолгов-с5о
    @АлексейДолгов-с5о 3 ปีที่แล้ว +1

    Thanks! You helped me out!)