package com.fdcis.test;
/**
* How to find 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);
System.out.print("Duplicate characters = ");
while(s.length()!=0){
char c=s.charAt(0);
if(s.indexOf(c,1)!=-1){
System.out.print(s.charAt(0)+" ");
}
if(s.charAt(0)=='.')
s=s.replaceAll("\\.","");
else
s=s.replaceAll(s.charAt(0)+"","");
}
}
}
How to find duplicate characters in a string in java? |
0 Comment to "How to find duplicate characters in a string in java?"
Post a Comment