Sunday, August 19, 2018

How to find duplicate characters in a string in java?




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?
How to find duplicate characters in a string in java?






Share this

0 Comment to "How to find duplicate characters in a string in java?"

Post a Comment