aspose file tools*
The moose likes Java in General and the fly likes Letters Frequency Counter Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Letters Frequency Counter " Watch "Letters Frequency Counter " New topic
Author

Letters Frequency Counter

alfonz jan frithz
Greenhorn

Joined: Apr 20, 2009
Posts: 20
I have several solution for this case actually. I just want to ask if this code "sexy" enough.
If you have suggestion, i really appreciate it...


Thanks...
Miklos Szeles
Ranch Hand

Joined: Oct 21, 2008
Posts: 142
Hi Alfonz,

I don't think this algorithm is too "sexy". It's very inefficient. You use a for loop in a for loop which runs through the text again and again and you do other unnecesseary operations.
You can do the counting part with one for loop and a Map. You run through the text with the loop and for every character you have 2 options:
1, Character not in the map, you put it into the map with a value of 1.
2, The Map contains the chraracter: You increment the stored value by one.
From the map you know the:
-number of different characters
-which are these characters
-how many of them you have
So you have all the necesseary information.
I hope it helps.
alfonz jan frithz
Greenhorn

Joined: Apr 20, 2009
Posts: 20
thanks for the solution... its cool man...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Letters Frequency Counter
 
Similar Threads
ByteArrayOutputStream
Writing a Recursive Descent Parser, I think I'm done, well almost?
i/o question
Return Statements problem
how to get rid of space in string