Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
HashMap<Character, Integer> mp = new HashMap<> ();
   for (int j = 0; j<text.length (); j++) {
       char ch = text.charAt(j);
          if(mp.containsKey(ch)){
                int cnt = mp.get(ch);
             mp.put(ch, ++cnt);
         }else{
            mp.put(ch, 1);
          }
}
Set<Character> charct = map.keySet();
 
for (Character ch: charct){
     int c= mp.get(ch);
     if(c>1){
        System.out.println(ch+ " - " + c);
     }
}


What I have tried:

I know that it is to get the matching characters in a string. But like to know more about it.
Posted
Updated 7-Nov-21 11:20am
v6
Comments
phil.o 7-Nov-21 17:13pm    
You already have been asked not to delete your questions after they have received some answers. So, please, stop doing it.
WillDavid 7-Nov-21 17:27pm    
Sorry sir, but i had too, i am planning to delete my current account and to create a new one so i can follow the rules i have known within these 2 or 3 days.

Thank you:
Will David

1 solution

That is code: so it is an example of code to solve whatever it is that code is meant to do.

If you mean "show an example of using this function" bay calling it an passing a valid parameter, then that is a task that has been set as homework - and if you read your course notes for the last lecture then a couple of minutes thinking should have it solved.

While we are more than willing to help those that are stuck, that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.

So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.
 
Share this answer
 
Comments
WillDavid 7-Nov-21 14:38pm    
Thank you, for the Respond i will try my best

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900