aspose file tools*
The moose likes Beginning Java and the fly likes Using HashMap need to count the frequency of letters in a String Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Using HashMap need to count the frequency of letters in a String" Watch "Using HashMap need to count the frequency of letters in a String" New topic
Author

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

Abhinav satyam Gupta
Greenhorn

Joined: Aug 15, 2008
Posts: 2
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

Joined: Nov 24, 2005
Posts: 14688
    
  16

Where did you get so far ?


[My Blog]
All roads lead to JavaRanch
Lucas Franceschi
Ranch Hand

Joined: Nov 10, 2008
Posts: 106

would you mind telling us a little more about your problem?, please help us, so that we can help you


Lucas Franceschi
Software Developer for SGI Sistemas, lukas1596@gmail.com
Steven Satelle
Greenhorn

Joined: Sep 30, 2008
Posts: 22
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

Joined: Oct 27, 2005
Posts: 19760
    
  20

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Balagopal Kannampallil
Ranch Hand

Joined: Oct 18, 2004
Posts: 136

Hi Abhinav,

Can you elaborate a little more about your requirement.


SCJP 5.0 and now fighting with ExtJS
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Using HashMap need to count the frequency of letters in a String