This week's book giveaway is in the Performance forum.
We're giving away four copies of The Java Performance Companion and have Charlie Hunt, Monica Beckwith, Poonam Parhar, & Bengt Rutisson on-line!
See this thread for details.
Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using HashMap need to count the frequency of letters in a String

 
Abhinav satyam Gupta
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Friends,

I wanted to write a prog which can count the frequency of letters in a String using HashMap.
Would seek your assistance to do so
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where did you get so far ?
 
Lucas Franceschi
Ranch Hand
Posts: 106
Mac Mac OS X Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
would you mind telling us a little more about your problem?, please help us, so that we can help you
 
Steven Satelle
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could try creating a HashMap<Character, int>, setting the keys to each letter your interested in. Then iterating through each Character in the String, and if (key<Character> .exists()) { value ++; }


now, there you go in sudo sudo code

 
Rob Spoor
Sheriff
Pie
Posts: 20546
57
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Steven Satelle wrote:You could try creating a HashMap<Character, int>, setting the keys to each letter your interested in. Then iterating through each Character in the String, and if (key<Character> .exists()) { value ++; }

That should be HashMap<Character, Integer> of course
And if the key does not exist, you have encountered the first occurrance. It's easy to determine what the value would have to be then.
 
Balagopal Kannampallil
Ranch Hand
Posts: 136
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Abhinav,

Can you elaborate a little more about your requirement.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic