Home > Algorithms > Remove duplicate characters in a string and display in the same order

Remove duplicate characters in a string and display in the same order

July 7, 2012

private String remove(String string) {
int a[] = new int[256];
int length = string.length();
String removedString = new String();
for(int i=0;i<length;i++){
char c = string.charAt(i);

if(a[c]==0) {
removedString = removedString +  c;
a[c]=1;
}
}
return removedString;

}
Advertisements
Categories: Algorithms Tags:
%d bloggers like this: