954,518 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

find the frequency of the character

String test="abacedabcedbcdea"

find the frequency of a , b ,c ,e and d

amarjeetsingh
Newbie Poster
21 posts since Feb 2009
Reputation Points: 2
Solved Threads: 1
 

4, 3, 3, 3 and 3

masijade
Industrious Poster
Moderator
4,253 posts since Feb 2006
Reputation Points: 1,471
Solved Threads: 494
 

You just count the number of times each one appears in the String. A simple web search would tell you that.

BestJewSinceJC
Posting Maven
2,772 posts since Sep 2008
Reputation Points: 874
Solved Threads: 354
 

I sure he knows that, he just wants a code handout. Which he won't get.

If he posts his attempt at it, he might get help correcting it, but noone is going to do it for him.

masijade
Industrious Poster
Moderator
4,253 posts since Feb 2006
Reputation Points: 1,471
Solved Threads: 494
 

Try this simple example:

String s = "asjdhk123uhmsmik,z!?";
for (int i=0;i<s.length();i++) {
  char ch = s.charAt(i);
  System.out.println(ch);
}


Also you should always check the API to find more methods that could be useful. In this case, you should have looked the String API

javaAddict
Nearly a Senior Poster
Team Colleague
3,329 posts since Dec 2007
Reputation Points: 1,014
Solved Threads: 448
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You