
Hi,
can one please share the code to count the occurance of each charaters in a given String??
For example: String is "aabbcad"
o/p will be:- a3b2c1d1 or a=3, b=2,c=1,d=1

public static void main(String[] args) {
String str="aabbcad";
for(int i=0;i<str.length();i++) {
char c=str.charAt(i);
boolean flag=true;
for(int j=0;j<i;j++){
char c1=str.charAt(j);
if(c==c1)
flag=false;
}
if(flag) {
int count=1;
for(int k=i+1;k<str.length();k++) {
char c2=str.charAt(k);
if(c==c2)
count++;
}
System.out.println(c+"="+count);
}
}

Thnx Deepak:)
can you please explain me the code shared above..