File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Strings Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Strings" Watch "Strings" New topic


Nickesha Lindsay

Joined: Dec 01, 2003
Posts: 6
I would like to know how do I go about getting specified letter from a word, then printing out how many times that letter shows up in the word.
String word = "Alabama";
System.out.println ("Letters in word: " + word);
I want to get only the letter 'a' from the word, so the result must print out the number "4", since there are 3 letters in the word 'Alabama'.
Could someone please give me some examples and how to start this program off?
Are there any String/Character classes I should be aware of to do this and if so, which ones?
Thank you
Brian Pipa
Ranch Hand

Joined: Sep 29, 2003
Posts: 299
Take a look at the Javadocs for String. Lots of good stuff there like:
.toLowerCase() (if you're not worried about case)
Try writing a for loop using the length() and take a look at each character with charAt()
That should get you started.

My Java Freeware:<br />MACCC - <a href="" target="_blank" rel="nofollow"></a><br />Nator - <a href="" target="_blank" rel="nofollow"></a>
I agree. Here's the link:
subject: Strings
It's not a secret anymore!