Java Program to Count Number of Duplicate Words in Given String

แชร์
ฝัง
  • เผยแพร่เมื่อ 21 ก.ค. 2024
  • Java Program to Count Number of Duplicate Words in Given String
    ~~~Subscribe to this channel, and press bell icon to get some interesting videos on Selenium and Automation:
    th-cam.com/users/Naveen%20Au...
    Follow me on my Facebook Page:
    / naveenqtpexpert
    Let's join our Automation community for some amazing knowledge sharing and group discussion on Telegram:
    t.me/joinchat/COJqZUPB02r5sB7...
    WebServices API Automation Tutorials:
    vimeo.com/ondemand/webservice... ~~~Subscribe to this channel, and press bell icon to get some interesting videos on Selenium and Automation:
    th-cam.com/users/Naveen%20Au...
    Follow me on my Facebook Page:
    / naveenqtpexpert
    Let's join our Automation community for some amazing knowledge sharing and group discussion on Telegram:
    t.me/joinchat/COJqZUPB02r5sB7...
    Paid courses (Recorded) videos:
    Java & Selenium Course: www.naveenautomationlabs.com/p...
    API Course: www.naveenautomationlabs.com/p... ➡️Get Our Courses✔️
    📗 Get My Paid Courses at
    Paid courses (Recorded) videos:
    Java & Selenium Course: www.naveenautomationlabs.com/p...
    API Course: www.naveenautomationlabs.com/p...
    -------------------------------
    ✔️SOCIAL NETWORKS
    Facebook: / naveenqtpexpert
    Twitter: / naveenkhunteta
    Blog: www.naveenautomationlabs.com
    --------------------------------
    Support My Channel✔️Or Buy Me A Coffee
    Paypal: paypal.me/naveenkhunteta
    Google Pay: naveenanimation20@gmail.com
    --------------------------------
    ✔️Thanks for watching!
    देखने के लिए धन्यवाद
    Благодаря за гледането
    感谢您观看
    Merci d'avoir regardé
    Grazie per la visione
    Gracias por ver
    شكرا للمشاهدة
  • วิทยาศาสตร์และเทคโนโลยี

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

  • @Tistasful
    @Tistasful 4 ปีที่แล้ว +4

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

  • @nagaswetha7564
    @nagaswetha7564 10 หลายเดือนก่อน +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.

  • @2anshumansehgal
    @2anshumansehgal 4 ปีที่แล้ว +1

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

  • @SarangHoley
    @SarangHoley 4 ปีที่แล้ว +1

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

  • @zareenabegum9095
    @zareenabegum9095 4 ปีที่แล้ว +1

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

  • @varshamishra8743
    @varshamishra8743 2 ปีที่แล้ว +2

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

  • @vetriselvansp8105
    @vetriselvansp8105 4 ปีที่แล้ว +1

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

  • @mohammadsuhail1371
    @mohammadsuhail1371 10 หลายเดือนก่อน

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

  • @IntellectOnly
    @IntellectOnly 4 ปีที่แล้ว +1

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

  • @EdClarkHYCT
    @EdClarkHYCT 4 ปีที่แล้ว +1

    Incredibly awesome video. Keep up the great work!

  • @divineIncarnation
    @divineIncarnation 4 ปีที่แล้ว +2

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

  • @karthickmohan8715
    @karthickmohan8715 4 ปีที่แล้ว

    Thank so much bro its very useful for my interview

  • @mamasahoo2897
    @mamasahoo2897 2 ปีที่แล้ว

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

  • @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.

  • @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.

  • @ramupanjala6003
    @ramupanjala6003 4 ปีที่แล้ว +1

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

  • @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

  • @pavankumarkj9865
    @pavankumarkj9865 4 ปีที่แล้ว +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!

  • @zakir7719
    @zakir7719 4 ปีที่แล้ว +1

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

  • @shravan6704
    @shravan6704 4 ปีที่แล้ว +1

    nice broo

  • @chaithracheth
    @chaithracheth 4 ปีที่แล้ว

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

  • @amolnawale2177
    @amolnawale2177 4 ปีที่แล้ว +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.

  • @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 4 ปีที่แล้ว

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

  • @bhuvanasekar603
    @bhuvanasekar603 11 หลายเดือนก่อน

    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);

  • @santoshkumarvlogs3753
    @santoshkumarvlogs3753 4 หลายเดือนก่อน

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

  • @WMohanty
    @WMohanty 3 ปีที่แล้ว

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

  • @imranullah7355
    @imranullah7355 ปีที่แล้ว

    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...

  • @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 :) 🙏

  • @shanthikandasamy
    @shanthikandasamy 4 ปีที่แล้ว

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

    • @payalmodi9377
      @payalmodi9377 4 ปีที่แล้ว

      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 4 ปีที่แล้ว

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

    • @shanthikandasamy
      @shanthikandasamy 2 ปีที่แล้ว

      @Sunaan S nope

  • @mohammadsuhail1371
    @mohammadsuhail1371 10 หลายเดือนก่อน

    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));
    }
    }

  • @himanshuthakur1605
    @himanshuthakur1605 3 หลายเดือนก่อน

    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