Posts
 
Reputation
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
~433 People Reached
Favorite Forums
Favorite Tags
java x 1

1 Posted Topic

Member Avatar for crestaldin

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]

Member Avatar for JamesCherrill
0
433

The End.