Joined
Last Seen
0 Reputation Points
0% Quality Score
- Upvotes Received
- 0
- Posts with Upvotes
- 0
- Upvoting Members
- 0
- Downvotes Received
- 1
- Posts with Downvotes
- 1
- Downvoting Members
- 1
0 Endorsements
Ranked #107.55K
1 Posted Topic
Re: Try this.. public void getFrequencyInString(){ String str = "apple"; HashMap hm = new HashMap(); for(int i = 0; i<str.length(); i++){ char c = str.charAt(i); if(hm.get(c)!= null){ hm.put(c, (Integer)(hm.get(c))+1); }else{ hm.put(c, 1); } } System.out.println(hm.entrySet()); } Output: [e=1, p=2, a=1, l=1] |
The End.