package com.cdcis.test;
/**
* How to count duplicate characters in a string in java?
*
*/
public class Test {
public static void main(String[] args) {
String s="altafjava.blogspot.com";
System.out.println("Original String = "+s);
int count=0;
for(int i=0;i<s.length();i++){
char c=s.charAt(i);
for(int j=1;j<s.length();j++){
if(s.charAt(i)==s.charAt(j)){
count++;
}
}
System.out.println(s.charAt(i)+" = "+count);
count=0;
s=s.replaceAll(Character.toString(s.charAt(i)),"");
}
}
}
How to count duplicate characters in a string in java? |
0 Comment to "How to count duplicate characters in a string in java?"
Post a Comment