
can u resolve anybody my problem is how to remove duplicate characters in 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);
}
}
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.