Java Program to Count Number of Duplicate Words in Given String

Поділитися
Вставка
  • Опубліковано 18 жов 2024

КОМЕНТАРІ • 44

  • @nagaswetha7564
    @nagaswetha7564 Рік тому +1

    The way you are explaining the logic while writing it is crystal clear even to a beginner. Thanks a lot for sharing all the videos. I have also tried the above program using Set and it worked.

  • @varshamishra8743
    @varshamishra8743 3 роки тому +2

    I am loving coding only because the way you explain every logic Sir... Thank you🙏

  • @Tistasful
    @Tistasful 5 років тому +4

    Thank you sharing your knowledge with the whole world, you are doing a great job and you are a role model!

  • @sankarsan
    @sankarsan 3 роки тому +2

    The best channel for Automation. Kudos to you Naveen. Keep up the good work.

    • @naveenautomationlabs
      @naveenautomationlabs  3 роки тому

      Thanks a ton

    • @sankarsan
      @sankarsan 3 роки тому +1

      For me you are a celebrity. The way you are gifting the knowledge unconditionally is invaluable. I remember one of the videos where you showed your hand writing notes during your stay in Pune. It seems everything is possible when it comes to Technology & Naveen.

  • @mohammadsuhail1371
    @mohammadsuhail1371 Рік тому

    TBH your code complexity is more challenging for beginner level coders But seriously it motivates to learn more and more...!! Thank you :)

  • @2anshumansehgal
    @2anshumansehgal 4 роки тому +1

    Thanks Naveen..your way of explaining things is too good!

  • @zareenabegum9095
    @zareenabegum9095 5 років тому +1

    Learned a lot from your videos Naveen, thanks for sharing your knowledge 📖📚📝

  • @SarangHoley
    @SarangHoley 5 років тому +1

    Very much thankful for the video, much needed small but most asked topic got covered 👍😊

  • @vetriselvansp8105
    @vetriselvansp8105 4 роки тому +1

    Thank you so much Naveen. 😍 you are helping out a lot of people 👏👏👏

  • @amolnawale2177
    @amolnawale2177 5 років тому +2

    Hi Naveen,
    I think this can be solved using Set also, without involving Map, as below:
    String[] strArray = inputString.split("\\s");
    HashSet set = new HashSet();

    for (String arrayElement : strArray)
    {
    if(!set.add(arrayElement))
    {
    System.out.println("Duplicate Element is : "+arrayElement);
    }
    }

    • @balakrishnan-jx2jp
      @balakrishnan-jx2jp 4 роки тому +1

      It is printing the duplicate elements, but where is the count.

  • @mamasahoo2897
    @mamasahoo2897 2 роки тому

    Always the best Naveen...you are superb...

  • @pavankumarkj9865
    @pavankumarkj9865 5 років тому +4

    To extract all the keys of map I have used Iterator and it’s really nice that it can be achieved using Set as well in simple way.
    Thank you so much Naveen Bhayya.

    • @007elya
      @007elya 4 роки тому

      Hi Pavan!
      Can you share your solution? Thanks!

  • @parimalaperiyasamy7859
    @parimalaperiyasamy7859 4 роки тому

    Hello Naveen,
    Thanks for your vedio. Its really understandable.Here are my questions, if you find time, please answer and that will help me.
    1. What is the role of toLowerCase() method here, Why its not converting upper case in input to Lowercase
    2. Can we use entrySet instead of Keyset for traversing the elements?

  • @anvitaravirajmetri8710
    @anvitaravirajmetri8710 3 роки тому

    Small Suggestion, If you explain the same thing with diagram of array and hashmap would give more clarification

  • @EdClarkHYCT
    @EdClarkHYCT 4 роки тому +1

    Incredibly awesome video. Keep up the great work!

  • @IntellectOnly
    @IntellectOnly 5 років тому +1

    Wonderful naveen. I'm a follower from dc. Great video. More!

  • @zakir7719
    @zakir7719 5 років тому +1

    Hi Naveen good explanation, is there any other method to find the duplicate.

  • @divineIncarnation
    @divineIncarnation 5 років тому +2

    Always so helpful videos for me. Thanks a ton :)

  • @ramupanjala6003
    @ramupanjala6003 5 років тому +1

    Thanks for the video .I am looking count JSON response duplicate ? Can we use this concept in groovy ?

  • @karthickmohan8715
    @karthickmohan8715 5 років тому

    Thank so much bro its very useful for my interview

  • @traghavendra9828
    @traghavendra9828 4 роки тому

    Hi Need answer for this question by using java
    Write a program to check the 10 digit mobile number if it contains more than 10 digits last digits should be subtracted and if it contains less than 10 digits prefix 0 should be added.

  • @chaithracheth
    @chaithracheth 5 років тому

    To extract those values
    Just print wordcount. It will shows how many times each word has been repeated (this is easy)

  • @bhuvanasekar603
    @bhuvanasekar603 Рік тому

    One more approach using hash set
    String line = "hey java is best java ";
    String[] afterSplit = line.split(" ");
    Set store = new HashSet();
    int count =0;
    for(String word : afterSplit) {
    if(store.add(word)==false) {
    count++;
    System.out.println(word);
    }
    }
    System.out.println(count);

  • @shravan6704
    @shravan6704 5 років тому +1

    nice broo

  • @mdrajeshwar1
    @mdrajeshwar1 2 роки тому

    I got one issue while finding duplicates , if we declare in the string " Java is java " that time it's not working, like java: 2 , I am trying to convert string first into lowercase but not get success. anyone help me, Thanks in advance

  • @pallabdutta7536
    @pallabdutta7536 5 років тому

    you added the key in lower case inside map....then why didnt it work for same word with upper case

  • @santoshkumarvlogs3753
    @santoshkumarvlogs3753 7 місяців тому

    line number 30 . How this is related to words[] ? I mean how these splitted words going into hashmap? Can anyone please let me know.

  • @imranullah7355
    @imranullah7355 2 роки тому

    You people can also count duplicate words in this way:
    public static String findingMatchingWords(String str)
    {
    int count =0;
    String Result = "";
    String strArray[] = str.split(" ");
    for (int i = 0; i < strArray.length; i++) {
    count = 1;
    for (int j = i + 1; j < strArray.length; j++) {
    if (strArray[i].equals(strArray[j])) {
    count++;
    strArray[j] = "0";
    }
    }
    if (count> 1 && strArray[i] != "0"){
    Result = strArray[i];
    System.out.println(Result+"----"+count);
    }
    }
    return Result;
    }
    public static void main(String[] args) {
    // call the function
    findingMatchingWords(" ");
    }
    Thank me later...

  • @WMohanty
    @WMohanty 3 роки тому

    I am not able to understand this. How it is comparing java to java, first time it will be come heyjava

  • @keralacodingacademykca4597
    @keralacodingacademykca4597 3 роки тому +1

    Found it really complicated

    • @keralacodingacademykca4597
      @keralacodingacademykca4597 3 роки тому +1

      Now it looks less complicated...did some digging...thankyou my friend!

    • @keralacodingacademykca4597
      @keralacodingacademykca4597 3 роки тому +1

      I used entrySet to use the getValue() method and used it in if.. to compare it to greatethan 1...and before that, itereated through the entrySet...stored the repeated word and count in variables..using set methods... .getKey() and .getValue()

    • @keralacodingacademykca4597
      @keralacodingacademykca4597 3 роки тому +1

      Your method is much less complex..I tried to use a file..instead of string..so hence bufferedReader came into the picture...its good that you used just hashmap and .get(key) which gives value instead of converting map to set...that's much simpler...thankyou!

    • @naveenautomationlabs
      @naveenautomationlabs  3 роки тому +1

      Most welcome :) 🙏

  • @mohammadsuhail1371
    @mohammadsuhail1371 Рік тому

    Question:- String name = "This is a sample sentence. This is another sentence";
    Answer:-
    sentence:-2
    a:-1
    another:-1
    this:-2
    is:-2
    sample:-1
    Below code will help.
    public static void main(String[] args) {
    String name = "This is a sample sentence. This is another sentence";
    String[] split = name.split(" ");
    Map mp = new HashMap();
    Pattern pattern = Pattern.compile("\\p{Punct}");
    for (String a : split) {
    String s = a.replaceAll("\\p{Punct}", "").toLowerCase();
    if (mp.containsKey(s)) {
    mp.put(s, mp.get(s) + 1);
    } else {
    mp.put(s, 1);
    }
    }
    Set Y = mp.keySet();
    for (String x : Y) {
    System.out.println(x + ":-" + mp.get(x));
    }
    }

  • @shanthikandasamy
    @shanthikandasamy 5 років тому

    How to split if there is no space in a given string..eg:javaislanguageisjava..

    • @payalmodi9377
      @payalmodi9377 5 років тому

      then it will be totally different question of finding duplicate letter in string. this one here is for words so there will always be space in between

    • @shanthikandasamy
      @shanthikandasamy 5 років тому

      @@payalmodi9377 yeah I understand this is for words..I just raised a question as there is a similarity in a concept

    • @shanthikandasamy
      @shanthikandasamy 3 роки тому

      @Sunaan S nope

  • @himanshuthakur1605
    @himanshuthakur1605 6 місяців тому

    public class DuplicateWordsWithOccurence {
    public static void main(String[] args)
    {
    printDuplicateWithOccurence("Noida is a good city and Is a good very good noida good and well maintained good");
    printDuplicateWithOccurence("Java Python java python");
    }
    public static void printDuplicateWithOccurence(String str1)
    {
    int count = 1;
    String str2[] = str1.split(" ");
    for(int i = 0; i