This content originally appeared on DEV Community and was authored by NJ
Code:
import java.util.*;
import java.lang.*;
class Demo{
public static void main(String[] args){
String name = "idiot";
Map<Character,Integer> map = new HashMap<Character,Integer>();
for(int i=0;i<name.length();i++){
Character ch = name.charAt(i);
map.put(ch,map.getOrDefault(ch,0)+1);
}
System.out.println(map);
for(Map.Entry<Character,Integer> e : map.entrySet()){
System.out.println(e.getKey()+" "+e.getValue());
}
}
}
o/p:
This content originally appeared on DEV Community and was authored by NJ
Print
Share
Comment
Cite
Upload
Translate
Updates
There are no updates yet.
Click the Upload button above to add an update.
APA
MLA
NJ | Sciencx (2023-04-27T02:54:51+00:00) how to find the frequency of characters in given string in java. Retrieved from https://www.scien.cx/2023/04/27/how-to-find-the-frequency-of-characters-in-given-string-in-java/
" » how to find the frequency of characters in given string in java." NJ | Sciencx - Thursday April 27, 2023, https://www.scien.cx/2023/04/27/how-to-find-the-frequency-of-characters-in-given-string-in-java/
HARVARDNJ | Sciencx Thursday April 27, 2023 » how to find the frequency of characters in given string in java., viewed ,<https://www.scien.cx/2023/04/27/how-to-find-the-frequency-of-characters-in-given-string-in-java/>
VANCOUVERNJ | Sciencx - » how to find the frequency of characters in given string in java. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2023/04/27/how-to-find-the-frequency-of-characters-in-given-string-in-java/
CHICAGO" » how to find the frequency of characters in given string in java." NJ | Sciencx - Accessed . https://www.scien.cx/2023/04/27/how-to-find-the-frequency-of-characters-in-given-string-in-java/
IEEE" » how to find the frequency of characters in given string in java." NJ | Sciencx [Online]. Available: https://www.scien.cx/2023/04/27/how-to-find-the-frequency-of-characters-in-given-string-in-java/. [Accessed: ]
rf:citation » how to find the frequency of characters in given string in java | NJ | Sciencx | https://www.scien.cx/2023/04/27/how-to-find-the-frequency-of-characters-in-given-string-in-java/ |
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.