
Hi, I am trying to remove duplicated charater from a given string without using built in function, but getting some issue in that. can anyone please share the code for that???
Thanks a lot in advance!!

Here is an example that removes the duplicate character from the string.
import java.util.*;
class RemoveDuplicateCharatcersFromString
{
public static String removeDuplicates(String s) {
StringBuilder build = new StringBuilder();
for (int i = 0; i < s.length(); i++) {
String st = s.substring(i, i + 1);
if (build.indexOf(st) == -1) {
build.append(st);
}
}
return build.toString();
}
public static void main(String[] args)
{
String str="Hello World";
String newString=removeDuplicates(str);
System.out.println(newString);
}
}

Hi,
Above code is not working if i Pass Sting value which is doesnot contains space.. like. ajitya
can any one please share the code to remove duplcaites charaters from a string??
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.