Java Program to Count Number of Duplicate Words in Given String

  Рет қаралды 62,669

Naveen AutomationLabs

Naveen AutomationLabs

Күн бұрын

Пікірлер: 44
@nagaswetha7564
@nagaswetha7564 Жыл бұрын
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 жыл бұрын
I am loving coding only because the way you explain every logic Sir... Thank you🙏
@Tistasful
@Tistasful 5 жыл бұрын
Thank you sharing your knowledge with the whole world, you are doing a great job and you are a role model!
@mohammadsuhail1371
@mohammadsuhail1371 Жыл бұрын
TBH your code complexity is more challenging for beginner level coders But seriously it motivates to learn more and more...!! Thank you :)
@sankarsan
@sankarsan 3 жыл бұрын
The best channel for Automation. Kudos to you Naveen. Keep up the good work.
@naveenautomationlabs
@naveenautomationlabs 3 жыл бұрын
Thanks a ton
@sankarsan
@sankarsan 3 жыл бұрын
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.
@amolnawale2177
@amolnawale2177 5 жыл бұрын
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 жыл бұрын
It is printing the duplicate elements, but where is the count.
@pavankumarkj9865
@pavankumarkj9865 5 жыл бұрын
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!
@2anshumansehgal
@2anshumansehgal 5 жыл бұрын
Thanks Naveen..your way of explaining things is too good!
@zareenabegum9095
@zareenabegum9095 5 жыл бұрын
Learned a lot from your videos Naveen, thanks for sharing your knowledge 📖📚📝
@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?
@SarangHoley
@SarangHoley 5 жыл бұрын
Very much thankful for the video, much needed small but most asked topic got covered 👍😊
@vetriselvansp8105
@vetriselvansp8105 4 жыл бұрын
Thank you so much Naveen. 😍 you are helping out a lot of people 👏👏👏
@anvitaravirajmetri8710
@anvitaravirajmetri8710 3 жыл бұрын
Small Suggestion, If you explain the same thing with diagram of array and hashmap would give more clarification
@zakir7719
@zakir7719 5 жыл бұрын
Hi Naveen good explanation, is there any other method to find the duplicate.
@mamasahoo2897
@mamasahoo2897 2 жыл бұрын
Always the best Naveen...you are superb...
@EdClarkHYCT
@EdClarkHYCT 4 жыл бұрын
Incredibly awesome video. Keep up the great work!
@ramupanjala6003
@ramupanjala6003 5 жыл бұрын
Thanks for the video .I am looking count JSON response duplicate ? Can we use this concept in groovy ?
@chaithracheth
@chaithracheth 5 жыл бұрын
To extract those values Just print wordcount. It will shows how many times each word has been repeated (this is easy)
@IntellectOnly
@IntellectOnly 5 жыл бұрын
Wonderful naveen. I'm a follower from dc. Great video. More!
@karthickmohan8715
@karthickmohan8715 5 жыл бұрын
Thank so much bro its very useful for my interview
@divineIncarnation
@divineIncarnation 5 жыл бұрын
Always so helpful videos for me. Thanks a ton :)
@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);
@traghavendra9828
@traghavendra9828 5 жыл бұрын
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.
@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...
@shravan6704
@shravan6704 5 жыл бұрын
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
@keralacodingacademykca4597
@keralacodingacademykca4597 3 жыл бұрын
Found it really complicated
@keralacodingacademykca4597
@keralacodingacademykca4597 3 жыл бұрын
Now it looks less complicated...did some digging...thankyou my friend!
@keralacodingacademykca4597
@keralacodingacademykca4597 3 жыл бұрын
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 жыл бұрын
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 жыл бұрын
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)); } }
@santoshkumarvlogs3753
@santoshkumarvlogs3753 8 ай бұрын
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
@himanshuthakur1605
@himanshuthakur1605 7 ай бұрын
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
@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
Some cool facts about Null in Java || Important to know
17:33
Naveen AutomationLabs
Рет қаралды 17 М.
Find Duplicate Characters In A String
8:10
CppNuts
Рет қаралды 12 М.
Увеличили моцареллу для @Lorenzo.bagnati
00:48
Кушать Хочу
Рет қаралды 7 МЛН
Каха и лужа  #непосредственнокаха
00:15
Twin Telepathy Challenge!
00:23
Stokes Twins
Рет қаралды 62 МЛН
27 - Java Program to find the duplicate words in a string.
17:07
Software Testing And Automation
Рет қаралды 13 М.
String Manipulation in Java - Interview questions - Part -7
25:21
Naveen AutomationLabs
Рет қаралды 111 М.
Check given String is a valid number in Java
19:57
Naveen AutomationLabs
Рет қаралды 12 М.
How to find Prime Number || Basic Programming Questions Series
20:37
Naveen AutomationLabs
Рет қаралды 82 М.
Reverse Sentence By Words - Logic Building Practice
6:49
CloudTech
Рет қаралды 23 М.
How to Find Duplicates Elements in Java Array? - Java Interview Questions -5
29:34
Difference between Interface and Absract Class
30:52
Naveen AutomationLabs
Рет қаралды 182 М.
Увеличили моцареллу для @Lorenzo.bagnati
00:48
Кушать Хочу
Рет қаралды 7 МЛН