Java Streams Interview Question - 06 - Print Duplicate Numbers using Streams

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

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

  • @vanishreeism
    @vanishreeism Год назад +3

    Actual filtering is happening due to the feature of set and due to Collections.frequency operation. To prove this try collecting it to a list instead of set

  • @amritapriyadarshini511
    @amritapriyadarshini511 3 года назад +1

    Thanks Naveen...One of my friend suggested me..to watch your videos which is so helpful for me.I got job.todY as automation engineer..thank you so much.

  • @AnilSharma-fb3ze
    @AnilSharma-fb3ze 3 года назад

    Thank you Naveen, it is greatful to use Streams

  • @mohammedsufi4649
    @mohammedsufi4649 Год назад

    Thank you so much for the video. Very useful. Please keep it up

  • @priyaranjan1973
    @priyaranjan1973 Год назад +3

    Set all=l.stream().filter(
    n-> l.stream().filter(x->x==n).count()>1
    ).collect(Collectors.toSet());

  • @prasantaweekends
    @prasantaweekends 2 года назад

    Thanks Naveen. It's very helpful

  • @deepanshurathore9661
    @deepanshurathore9661 2 года назад +2

    I think Set method is optimised take O(n) time . freq method might be take O(n2) time

  • @vengateshm2122
    @vengateshm2122 3 года назад +1

    Very useful. Thank you.

  • @muthikinaveen2195
    @muthikinaveen2195 Год назад +1

    Can you please explain using stream how find out highest occurrence number in array

  • @arunsinghrajpoot5363
    @arunsinghrajpoot5363 2 года назад +1

    Thanks bro

  • @smsms8522
    @smsms8522 Год назад +1

    We have distinct functionality in streams. numbers.stream().distinct();

  • @ankarigaripriyanka8306
    @ankarigaripriyanka8306 3 года назад +2

    never heard we could do it this way also

  • @sanoopk8847
    @sanoopk8847 3 года назад

    Waiting for more videos

  • @mastermind6269
    @mastermind6269 7 месяцев назад

    second solution would not work if we have accourence more than two times, we have to use distinct() method there!

  • @madarauchiha-dr5ws
    @madarauchiha-dr5ws Год назад

    No need to use collectors.toset(), collectors.toList() will work. Can someone please correct me if I am wrong

    • @ruishizhang1159
      @ruishizhang1159 Год назад

      List won't work if there is a tripled number

  • @karamjitsinghsehdev3451
    @karamjitsinghsehdev3451 2 года назад

    How to get duplicates with their counts and return map?

  • @priyansusekhar6123
    @priyansusekhar6123 3 месяца назад

    your teaching is very helpful but i think sir u don't know about distinct() method......

  • @vinayfartyal3666
    @vinayfartyal3666 21 день назад

    Set set = new HashSet();
    return list.stream().filter(num -> !set.add(num)) // Keep only duplicates
    .distinct() // to ensure unique duplicates
    .toList();