Frequently Asked Java Program 26: How To Count Occurrences of a Character in a String

  Рет қаралды 216,263

SDET- QA

SDET- QA

Күн бұрын

Пікірлер: 67
@shakulhameed1767
@shakulhameed1767 3 жыл бұрын
we simply sovle the problem like int count =s.replaceAll("[^a]","").length();
@ayushpandeyg
@ayushpandeyg 2 жыл бұрын
That's professional 👍👍
@j_j8758
@j_j8758 Жыл бұрын
Wowww that was good!
@Himu421
@Himu421 Жыл бұрын
Amazing video sir ! You code in such simple way and explain it so well that any basic /intermediate base person can fully grasp the concept and learn coding.
@sdetpavan
@sdetpavan Жыл бұрын
Thanks
@nayabshaik2282
@nayabshaik2282 Жыл бұрын
I was very scary to make understand coding earlier. But once I started watching your videos, my thought process changed. I am very comfortable to understand your logics, I feel like "OH CODING IS SUCH SIMPLE" 😄🤣 Great Thank you Pavan sir..🤝🤝🙏🙏
@CareerHirings
@CareerHirings Жыл бұрын
why writing this much complex...i dont know............ we can write in this way too String s="yash is a good boy "; char comp='a'; int flag=0; for(int i=0;i
@akadeadahot7067
@akadeadahot7067 4 жыл бұрын
this method is also easy check it guys' String str="java programming is very easy"; int count=0; for(int i=0;i
@janetbawuah8981
@janetbawuah8981 4 жыл бұрын
thanks it worked.
@udaybenake206
@udaybenake206 3 жыл бұрын
This is working but does not count uppercase characters if we are pass lowercase or vice versa
@TheCrazyRitik
@TheCrazyRitik 2 жыл бұрын
@@udaybenake206 because java is case sensitive A and a both are different
@f.a5148
@f.a5148 Жыл бұрын
@@udaybenake206 use this for Upper case or lower case: if(str.charAt(i)=='a' || str.charAt(i) == 'A')
@f.a5148
@f.a5148 Жыл бұрын
thanks man this is much easier.
@AaminaSadiya-v5e
@AaminaSadiya-v5e 10 ай бұрын
Superb easy to understand sir...thanks a lot for helping us.
@sdetpavan
@sdetpavan 10 ай бұрын
Welcome
@Canada1989
@Canada1989 3 жыл бұрын
This was asked in my interview
@Nmx7428
@Nmx7428 2 жыл бұрын
This is asked in my interview too with 5year experience
@Shreenidhi110
@Shreenidhi110 10 ай бұрын
Thank you so much,very easy way to understand
@sdetpavan
@sdetpavan 10 ай бұрын
Welcome
@pakkaandhrapori3768
@pakkaandhrapori3768 4 жыл бұрын
Thanks for easy explanation and can we do the same program without "replace" method? please explain the approach as well
@bharathkoneru4008
@bharathkoneru4008 4 жыл бұрын
We can do it by converting the given String to character array and then search for element. Increment the count when the element is found.
@suprem3g4mer6
@suprem3g4mer6 3 жыл бұрын
@@bharathkoneru4008 how
@emmadivamshi1798
@emmadivamshi1798 Жыл бұрын
Sir Your explanation is very nice and am very thankful to you sir
@sdetpavan
@sdetpavan Жыл бұрын
It's my pleasure
@rameshtirneddi5624
@rameshtirneddi5624 2 жыл бұрын
if we get string from the user then how to get max occuring character
@abinayabala6868
@abinayabala6868 4 жыл бұрын
can u tell me how to check for all the character occurence
@swayamprakashbhuyan2580
@swayamprakashbhuyan2580 3 жыл бұрын
Love your videos and commenting for better reach. You have a great voice btw.
@sdetpavan
@sdetpavan 2 жыл бұрын
Thanks
@vikramsinghyadav7793
@vikramsinghyadav7793 Жыл бұрын
Sir we can use Hashmap that would be more efficient
@tejajami6729
@tejajami6729 11 ай бұрын
import java.util.Arrays; class OccrenceOfInputArray { public static void main(String[] args) { int arr[] = {1, 1, 2, 2, 3, 4, 5, 6, 8, 9}; int len = arr.length; System.out.println("Total length: " + len); String arrString = Arrays.toString(arr); // Replace '2' with an empty string and get the length int totalCount = len - arrString.replace("2", "").length(); System.out.println("Total count of 2: " + totalCount); } } sir, while im running this program after removing the 2 we got the output is 8, but here output is getting is: -18..........please clarify this doubt sir
@hemrajpatil782
@hemrajpatil782 3 жыл бұрын
very easy sir.thank u. sir can u please make programm for prime no. from array ..please sir .
@SaisowmyaPriya
@SaisowmyaPriya Жыл бұрын
hi sir can we use this method is scanner sirif yes can u tell me how to use it
@v2factsand327
@v2factsand327 Жыл бұрын
Excellent explanation
@sdetpavan
@sdetpavan Жыл бұрын
Glad it was helpful!
@rizwanreshi8673
@rizwanreshi8673 Жыл бұрын
Sir what about when there are same letter with upper and lower case.
@vladshome
@vladshome Жыл бұрын
you can use the ".toLowerCase()" method on the string, before removing the character you're counting. it will make the whole String lowercase
3 жыл бұрын
Tell for all character occurences. For all occurences it will become a very exhausting code
@vithvishnu1497
@vithvishnu1497 4 жыл бұрын
Can i get this in loop.. if yes can u comment the statement..
@udaybenake206
@udaybenake206 3 жыл бұрын
This is working but does not count uppercase characters if we are pass lowercase or vice versa
@rohanmane7423
@rohanmane7423 2 жыл бұрын
Do s=s.toLowerCase(); /toUpperCase();
@MB-zt7cd
@MB-zt7cd 4 жыл бұрын
Nice explanation however I am bit confused, as we count the spaces as well in index., So when we are replacing a with space, the space would still be counted. so not sure how did it work. Could you please explain the logic for that. Thank you
@avinashhr
@avinashhr 4 жыл бұрын
He is not replacing with space its null.
@bharathkoneru4008
@bharathkoneru4008 4 жыл бұрын
Its not replacing with space, a is replaced with empty(""). space means " " empty means ""
@pawan_288
@pawan_288 3 ай бұрын
good
@osaimurari3485
@osaimurari3485 Ай бұрын
burra padu sir!
@gayathridhana1000
@gayathridhana1000 Жыл бұрын
sir please make more interview programs
@NiteshKumar-vz8uy
@NiteshKumar-vz8uy Жыл бұрын
This question asked me today
@ravindrakawale5161
@ravindrakawale5161 2 жыл бұрын
Great explain....🙌🙌
@sdetpavan
@sdetpavan 2 жыл бұрын
Glad it was helpful!
@vs4084
@vs4084 3 жыл бұрын
Thankyou sir for this video...
@sdetpavan
@sdetpavan 2 жыл бұрын
Most welcome
@shraddhaprabhu9033
@shraddhaprabhu9033 Жыл бұрын
Sir make program video of duplicate characters in a string
@zishanalam8277
@zishanalam8277 2 жыл бұрын
What about no case sensitive
@krishdeepika6967
@krishdeepika6967 Жыл бұрын
Not working giving output as zero
@kvnagendra5354
@kvnagendra5354 4 жыл бұрын
Nice explanation
@sdetpavan
@sdetpavan Жыл бұрын
Thanks
@magicalmagie2889
@magicalmagie2889 2 жыл бұрын
Sir y u removing a es
@groundlevel1817
@groundlevel1817 2 жыл бұрын
impressive.
@sdetpavan
@sdetpavan 2 жыл бұрын
thanks
@ananya8672
@ananya8672 11 ай бұрын
not a good approach
@iliveinacrowdedhouse368
@iliveinacrowdedhouse368 4 жыл бұрын
Bonne vidéo
@bidya74
@bidya74 2 жыл бұрын
corrupted
@kvelez
@kvelez Жыл бұрын
import java.util.HashMap; import java.util.Scanner; public class Main { public static void main(String[] args) { System.out.print(" Enter a statement: "); Scanner scan = new Scanner(System.in); String statement = scan.nextLine(); scan.close(); String[] words = statement.split("\\s+"); HashMap wordHashMap = new HashMap(); HashMap letterHashMap = new HashMap(); for (int i = 0; i < statement.length(); i++){ char currentChar = statement.charAt(i); if (letterHashMap.containsKey(currentChar)){ letterHashMap.put(currentChar, letterHashMap.get(currentChar) + 1); } else { letterHashMap.put(currentChar, 1); } } for (Character letter : letterHashMap.keySet()){ int count = letterHashMap.get(letter); System.out.println("Letter: " + letter + " appears " + count + " times."); } for (String word : words){ if (wordHashMap.containsKey(word)){ wordHashMap.put(word, wordHashMap.get(word) + 1); } else { wordHashMap.put(word, 1); } } for (String item : wordHashMap.keySet()){ int count = wordHashMap.get(item); System.out.println("Word: " + item + " appears: " + count + " times."); } } }
@MAGAVISHNUT
@MAGAVISHNUT 2 жыл бұрын
This for known statement.. Then what is code for when we use scanner Class
Java Program To Find Occurrence Of Each Character | Ashok IT
18:15
小丑家的感情危机!#小丑#天使#家庭
00:15
家庭搞笑日记
Рет қаралды 30 МЛН
1 сквиш тебе или 2 другому? 😌 #шортс #виола
00:36
Бенчик, пора купаться! 🛁 #бенчик #арти #симбочка
00:34
Симбочка Пимпочка
Рет қаралды 2,9 МЛН
Миллионер | 2 - серия
16:04
Million Show
Рет қаралды 1,2 МЛН
String Interview Question: Count the occurrences of a character in a String
13:28
Solve String Programs in Java
14:37
Simply Coding
Рет қаралды 94 М.
Learn JSON in 10 Minutes
12:00
Web Dev Simplified
Рет қаралды 3,2 МЛН
Write Java program to count Character Occurrences in given string
8:00
Crack Testing Interview
Рет қаралды 35 М.
小丑家的感情危机!#小丑#天使#家庭
00:15
家庭搞笑日记
Рет қаралды 30 МЛН