> Hi All,
>
> I want to write a program wherein I can check the
> occurrences of every character in the string given.
>
> What should I do, is there a in built function to do
> this.
>
> Please help
There are lots of useful String functions available. You could try looking at the String api.
> I want to write a program wherein I can check the
> occurrences of every character in the string given.
What does this mean? Do you want each character split off separately. Do you want to count how many times each character appears? Do you want to find out if a particular character appears in the String?
I wrote this program and this works fine... Thanks
public class Main_Character_Occurence
{
public static void main(String args[])
{
String inputString = " Test String";
String matches = "abcdefghijklmnopqrstuvwxyz";
int sum = 0;
for (int i = 0; i < matches.length(); i++)
{
for (int ctr = 0; ctr < inputString.length(); ctr++)
{
if (matches.charAt(i) == Character.toLowerCase(inputString
.charAt(ctr)))
sum++;
}
System.out.println(matches.charAt(i) + "=" + sum);
sum = 0;
}
}
}
The output I am getting is this
a=0
b=0
c=0
d=0
e=1
f=0
g=1
h=0
i=1
j=0
k=0
l=0
m=0
n=1
o=0
p=0
q=0
r=1
s=2
t=3
u=0
v=0
w=0
x=0
y=0
z=0