How to find the maximum occurring character in a String using Maps in java | strings programs | ABC

  Рет қаралды 38,846

ABC - Technology Training & Upskilling

ABC - Technology Training & Upskilling

Күн бұрын

Пікірлер: 27
@ABCforTechnologyTraining
@ABCforTechnologyTraining 5 жыл бұрын
Learn from Leaders, Learn from ABC. Watch our latest technical videos in your language: For Hindi:- bit.ly/2TRuGVP For Kannada:- bit.ly/31NH63M For Telugu:- bit.ly/2MuYRRP For Tamil:- bit.ly/2Num5Hz
@fanalu8788
@fanalu8788 4 жыл бұрын
I am just a beginner, just following your series help me understand a lot more than just reading the answers. Thanks a lot.
@ashishsuman7079
@ashishsuman7079 4 жыл бұрын
what if 2 characters occurs highest number of times in the string ?
@rajatbatra2256
@rajatbatra2256 4 жыл бұрын
Thanks for such a awesome series sir.. it's really helpful...you are doing a great job by keeping education and.technology side by side..this is one.of.the best tutorial on KZbin.
@ABCforTechnologyTraining
@ABCforTechnologyTraining 4 жыл бұрын
Thanks for acknowledging our efforts, Rajat! Edutainment is the new form of education to both educate as well as amuse. Keep watching, Keep learning!
@sibisidharth4933
@sibisidharth4933 4 жыл бұрын
for iteration we have to use entry set function for(Map.Entry data:lhmap.entrySet())
@ankitpandit5998
@ankitpandit5998 4 жыл бұрын
Good way to teach
@MdAzad-hb7vc
@MdAzad-hb7vc 4 жыл бұрын
Fabulous way of teaching!! But this code leaves an edge-case.. as in, it would not be able to print multiple max occurring characters.
@MdAzad-hb7vc
@MdAzad-hb7vc 4 жыл бұрын
Settmap = wMap.entrySet(); int counter =0; for ( Map.Entry data :tmap){ if (data.getValue() > counter ) { counter = data.getValue(); } } // iterates through the map again, to find key/keys with the counterValue. for (Map.Entry data2 : tmap){ if (data2.getValue() == counter) System.out.print(data2.getKey() ); }
@MdAzad-hb7vc
@MdAzad-hb7vc 4 жыл бұрын
Well, there is a much easier approach than what i just wrote above! Settmap = wMap.entrySet(); int counter =0; char val = ' '; for ( Map.Entry data :tmap){ if (data.getValue() >= counter ) { counter = data.getValue(); val = data.getKey(); System.out.print(val); } }
@ankitshrivastava1772
@ankitshrivastava1772 4 жыл бұрын
Excellent.
@ABCforTechnologyTraining
@ABCforTechnologyTraining 4 жыл бұрын
Thanks for listening. Happy learning!
@shashikiranb4230
@shashikiranb4230 4 жыл бұрын
U ARE AWESOME ...
@business187
@business187 5 жыл бұрын
CAN U plzzz MAKE TUTORIALS ALGORITHM?? Plzzzzzzzzzzz
@rajatbatra2256
@rajatbatra2256 4 жыл бұрын
What if 2 characters are repeating maximum.no.of.time???
@nimasherpa6093
@nimasherpa6093 5 жыл бұрын
What would have if more than single character have it's maximum value The same instructor of code is not giving the desire output
@srinivaskatam998
@srinivaskatam998 4 жыл бұрын
Same doubt for me bro .....if any knows, please explain....
@jhansiranikavali2709
@jhansiranikavali2709 4 жыл бұрын
sir what if we have more than most repeating characters? also how to find the least repeating characters if the string contains more then one characters????
@prachigarg1400
@prachigarg1400 5 жыл бұрын
Sir, how can we find the second highest occurring character in a string ??
@jamesbonding3988
@jamesbonding3988 4 жыл бұрын
get the top 1 .. then remove the top 1 or filter .. run again your algo .. then you got the 2nd one :) or you do a sort by value place a rank
@abdullahbaabbad885
@abdullahbaabbad885 4 жыл бұрын
This is another logic Since we put the variables in the map by making use of newval variable it means newval variable contains the maximum value in which the character has been occuring. Hence we will just compare it with other values and print it the code is: public class test { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("Enter your String"); String s = sc.nextLine(); s = s.toLowerCase(); char c[] = s.toCharArray(); int newval = 0; Map map = new HashMap(); for (int i = 0; i < s.length(); i++) { if (map.containsKey(c[i]) == false) { map.put(c[i], 1); } else { int oldval = map.get(c[i]); newval = oldval + 1; map.put(c[i], newval); } } Set hmap = map.entrySet(); for (Map.Entry data : hmap) { if (data.getValue() == newval) { System.out.print(data.getKey()); System.out.println(data.getValue()); } } } }
@DhanaLakshmi-lw7xo
@DhanaLakshmi-lw7xo 4 жыл бұрын
no its not working check with thiss input aaaahhhhhhhhhjjjj
@maksaini7515
@maksaini7515 5 жыл бұрын
char maxkey =' '; giving error how to resolve it.
@ABCforTechnologyTraining
@ABCforTechnologyTraining 5 жыл бұрын
Please share your complete program code here. We'll fix the errors for you.
@DhanaLakshmi-lw7xo
@DhanaLakshmi-lw7xo 4 жыл бұрын
give space between quotes
@nikunjgupta2878
@nikunjgupta2878 5 жыл бұрын
Sir ye program run hi nahi ho Raha h 😥😥
@vybhavavenkatesh7703
@vybhavavenkatesh7703 4 жыл бұрын
Add an iterator before the foreach loop.
How to print duplicate characters present in a String using Maps in java | strings programs in java
8:51
ABC - Technology Training & Upskilling
Рет қаралды 24 М.
Java Program To Find Occurrence Of Each Character | Ashok IT
18:15
Миллионер | 3 - серия
36:09
Million Show
Рет қаралды 2 МЛН
Молодой боец приземлил легенду!
01:02
МИНУС БАЛЛ
Рет қаралды 1,9 МЛН
Pangram Program in Java | Pangram Problem Solution | Interview Questions on Pangram | ABC
16:53
ABC - Technology Training & Upskilling
Рет қаралды 56 М.
Introduction to MAP Data Structure in Java | HashMap in Java with Example | ABC
12:40
ABC - Technology Training & Upskilling
Рет қаралды 44 М.
Loops in Java | for | while | do-while | for-each loop in java | loops in java programming | ABC
13:56
ABC - Technology Training & Upskilling
Рет қаралды 24 М.
Accessing the Data in MAP Data Structure | Applications of Maps in Java | Java Beginners Tutorial
8:29
ABC - Technology Training & Upskilling
Рет қаралды 35 М.
How to STUDY so FAST it feels like CHEATING
8:03
The Angry Explainer
Рет қаралды 1,8 МЛН
Миллионер | 3 - серия
36:09
Million Show
Рет қаралды 2 МЛН