Java Interview Question: How To Count Occurrences Of Each Character In String In Java

  Рет қаралды 96,639

Naveen AutomationLabs

Naveen AutomationLabs

Күн бұрын

Пікірлер: 54
@sanghamitrabhowmicklive3013
@sanghamitrabhowmicklive3013 3 жыл бұрын
All my interest in Java is because of you. I can't thank you enough for all that you have done for us!! 👏
@909praveen
@909praveen 3 жыл бұрын
Thanks Naveen for the video . For the assessment we just have to remove not symbol from if(String.valueOf(c).is blank()).
@surabhibn541
@surabhibn541 2 жыл бұрын
Your approach is really so easy to understand and you solve the program in most efficient way too Thank you so much...
@shashikumarkondoju7808
@shashikumarkondoju7808 3 жыл бұрын
Thankyou sir the way you explained awesome..it's makes every one to easy understand... For only spaces count we use instead of not if condition if(String.valueOf(ch).isBank())
@antarabanerjee7314
@antarabanerjee7314 3 жыл бұрын
Thanks for the explanation Naveen. It's because of you, yesterday I cracked one more interview!
@naveenautomationlabs
@naveenautomationlabs 3 жыл бұрын
Many congratulations 👍
@antarabanerjee7314
@antarabanerjee7314 3 жыл бұрын
@@naveenautomationlabs thank you so much!
@cngramesh
@cngramesh 4 ай бұрын
For checking space, replace "a" with space : String str = "this is a java programming"; int result = str.length()- str.replaceAll("a", "").length(); System.out.println(result);
@lavanya.ds0657
@lavanya.ds0657 3 жыл бұрын
Thank you souch for sharing this Naveen, this is mandatory question asked in many interviews for experienced candidates
@anilds2631
@anilds2631 Жыл бұрын
solution for counting space int count=0; for(char ch:name.toCharArray()) { if(ch==' ') { count++; } } System.out.println("******************"); System.out.println(count);
@somrajyadav2446
@somrajyadav2446 2 жыл бұрын
Thank you Naveen!! God bless you 🙏
@NagarajuN-ev3pl
@NagarajuN-ev3pl 7 ай бұрын
Hi NAVEEN, Good day! The same program I was facing in the technical round and I wrote and explained to the interviewer. I cracked and cleared the first round as well. Thank you, please post more mock interviews. Thanks a lot..
@anilds2631
@anilds2631 Жыл бұрын
Solution for only space we need to take count of string and replaceall method int n=name.length()-name.replaceAll(" ", "").length(); System.out.println("spaceCount"); System.out.println(n);
@ParamjitKaur-jo2sz
@ParamjitKaur-jo2sz 2 жыл бұрын
To count only spaces, we will remove NOT from condition like below if(String.valueOf(c).isBlank())
@MrAshu58
@MrAshu58 3 жыл бұрын
I am well versed in Python, Should I learn Java as well?
@naveenautomationlabs
@naveenautomationlabs 3 жыл бұрын
Yes if you trying for Selenium. Selenium with java is the most demanding as compared to other language bindings.
@thatsdeep7058
@thatsdeep7058 2 жыл бұрын
YOU'RE THE MAN!!, THANK YOU!!!!!!!!!!!! but why u had to test ur code for 10 min lol
@aayushpatel3360
@aayushpatel3360 3 жыл бұрын
Best approach
@arunkumar-ke3km
@arunkumar-ke3km 4 ай бұрын
veryuseful video,
@13success66
@13success66 2 жыл бұрын
Beautiful explanation
@ShashiBhushanSrivastava001
@ShashiBhushanSrivastava001 3 жыл бұрын
Thanks Naveen.
@ashuiet
@ashuiet 3 жыл бұрын
most of the interview this question asked ...if not this then ...some what similar to this problem.
@vigneshlakshmipathi2689
@vigneshlakshmipathi2689 3 жыл бұрын
Thank you so much naveen😍
@khajazakiuddin931
@khajazakiuddin931 3 жыл бұрын
Thank you so much for the amazing videos on Java concepts Naveen. it really helps in improving my coding skills. Could you also please make a video on how to print all the permutations of a given string "abc" (like acb, bca, cab, cba..etc.,). (It was asked in the interview with ADP company). There are many logics present on the internet but not fully understandable, just wanted to get it from you which obviously would be easy to understand and implement.
@Wandereatstravel
@Wandereatstravel 2 жыл бұрын
Print occurences of each word and character in a string : it was asked in the interview
@fariyabkhan8095
@fariyabkhan8095 3 ай бұрын
thank you brother
@parthjadhav2501
@parthjadhav2501 2 жыл бұрын
veryyy very nice explaination
@sayyedfiroz7556
@sayyedfiroz7556 3 жыл бұрын
Very nice video Naveen
@programminghubbharat7535
@programminghubbharat7535 2 жыл бұрын
Yes sir, by just removing the (!) In the if(!string.valueof(c).isBlank()) we got only spaces
@devanandthirunavukkarasu5148
@devanandthirunavukkarasu5148 2 жыл бұрын
sir. thanks for the video .can we do this in java 8
@ashuiet
@ashuiet 3 жыл бұрын
Thanks!
@aparna5088
@aparna5088 9 ай бұрын
This program is case sensitive the uppercase and lowercase occurences of same letters are counted seperately.
@varshamishra8743
@varshamishra8743 3 жыл бұрын
Thank you Sir.. Nice video 👍😊
@ananthvraj183
@ananthvraj183 2 жыл бұрын
simple remove ! in (String.valueOf(C).isBlank()){} condtion
@lathaa890
@lathaa890 3 жыл бұрын
Make a video for String Builder and String Buffer bro.
@Gagana_Tgk
@Gagana_Tgk 2 жыл бұрын
String S1="hello" String S2="12345" Output=h1e2l3l4o5. Can you plz write program for above output
@lalitjadaunreaction014
@lalitjadaunreaction014 Жыл бұрын
bhai simple hai 1 loop creta karlo then bhs ek character fist string sai or 2nd character from 2 string using charAt[i]. simple sa trika to ye hai . or bhi efficienct way
@mohankumarrewatkar2824
@mohankumarrewatkar2824 3 жыл бұрын
Hello Naveen thanks for this video.. One interview que...if u can try for us... String str[]={"Suresh:20","Ramesh:10","Anand:05"} We want to sort the str array on the basis of age....
@mertm2245
@mertm2245 2 жыл бұрын
String str[]={"Suresh:20","Ramesh:10","Anand:05"}; List list= new ArrayList(); for(String s:str){ list.add(Integer.parseInt(s.substring(str[0].indexOf(":")+1))); } Collections.sort(list); String str2[]=new String[str.length]; for(int i=0;i
@VivekKumar-bu6ho
@VivekKumar-bu6ho Жыл бұрын
Sir, how can i get output as te2s3h if input is teesssh with stream ??
@haribabuvelakavaram5935
@haribabuvelakavaram5935 3 жыл бұрын
Hi Naveen, Just a question.. For thr first test case i.e input "test" the output Hashmap values must be {(t,1)(e,1)(s,1)(t,2)} .. right?? Because we are just adding a new key value pair to the hashmap but we are not updating the existing key-value pairs as per this code... For the 4th input character : 't' it will check if 't' is already present in the map. Since it is already there, it will fetch it's value which is 1 and then increments it by 1..so it will become 2 and will update a new key-value pair as( t,2) to the existing hashmap...so the final hashmap output should be {(t,1)(e,1)(s,1)(t,2)} .. Please explain how it is giving {(e,1)(s,1)(t,2)} as output.. Thanks in advance.
@SurajSharma-fw5fg
@SurajSharma-fw5fg Жыл бұрын
Because he is using HashMap and HashMap can not contain duplicate "key". Hence, only one 't' will be there in HashMap.
@sruthibhagavatula2450
@sruthibhagavatula2450 3 жыл бұрын
Why did you give only hash map? And how to choose which map to use in which scenario?
@anantpandey309
@anantpandey309 2 жыл бұрын
Hi Naveen, I m getting error while using the isBlank() method. Error showing that method isBlank() is undefined for type string.
@vijaykanthperikala
@vijaykanthperikala 3 жыл бұрын
Hi Naveen, I'm getting below error when I try to use "is Blank()" method. "The method isBlank() is undefined for the type String" Could you please help me ? I'm using jdk 1.8.0-301 version
@STUDIES-wv4mw
@STUDIES-wv4mw 11 ай бұрын
public static void spaceCount(String str) { int count = 0; char[] c = str.toCharArray(); for (char ce : c) { if (ce == ' ') { count++; } } System.out.println("Space Count " + count); }
@utkarshpatil2674
@utkarshpatil2674 11 ай бұрын
Answer to the assignment, please do correct otherwise import java.util.HashMap; import java.util.Map; public class charCount { public static void getCharCount(String name) { Map charMap=new HashMap(); char strArray[]=name.toCharArray(); for(char c: strArray) { if(String.valueOf(c).contains(" ")) { if(charMap.containsKey(c)) { charMap.put(c , charMap.get(c)+1 ); } else { charMap.put(c, 1); } } } System.out.println(name + " : " + charMap); } public static void main(String[] args) { // TODO Auto-generated method stub getCharCount("sel sel sel"); } }
@saikumar-io7un
@saikumar-io7un 2 жыл бұрын
Better, u can do videos for Less time
@ravi54217
@ravi54217 3 жыл бұрын
public class CharCount { public static void main(String[] args) { System.out.println(countBy(" This is a string ", Character::isSpaceChar)); } private static long countBy(final String string, final IntPredicate condition) { return string.chars().filter(condition).count(); } }
@codingsskills.explore
@codingsskills.explore 2 жыл бұрын
1 2 three 3 4 three 5 6 three 7 8 three.......20.anyone can solve this please aisa output aana chahiye
@district_gamer
@district_gamer 2 жыл бұрын
sir ap hindi main bnao yr video
@ManishaTech2.O-x4h
@ManishaTech2.O-x4h 2 ай бұрын
Class CountCharacters{ public static void getCharCount(String name){ HashMap map=new HashMap(); char[] ch=name.toCharArray(); for(char c: ch){ if(map.containsKey(c)){ map.put(c, map.get(c)+1)} else{ map.put(c,1)} } Sysem.out.println(name:"" +map);} public static void main(String[] args){ getCharCount("TestMock");}}
Reverse A Number using Recursion - Java Interview Question
5:59
Naveen AutomationLabs
Рет қаралды 21 М.
How to Find Duplicates Elements in Java Array? - Java Interview Questions -5
29:34
Увеличили моцареллу для @Lorenzo.bagnati
00:48
Кушать Хочу
Рет қаралды 8 МЛН
Can You Find Hulk's True Love? Real vs Fake Girlfriend Challenge | Roblox 3D
00:24
Муж внезапно вернулся домой @Oscar_elteacher
00:43
История одного вокалиста
Рет қаралды 5 МЛН
Find Duplicate Elements in An Array || Important Java Interview Questions
22:36
Naveen AutomationLabs
Рет қаралды 52 М.
Java Program To Find Occurrence Of Each Character | Ashok IT
18:15
Learn JSON in 10 Minutes
12:00
Web Dev Simplified
Рет қаралды 3,2 МЛН
Get the maximum word count in a text file || The most repeated word in a file
23:12
Увеличили моцареллу для @Lorenzo.bagnati
00:48
Кушать Хочу
Рет қаралды 8 МЛН