remove all duplicates from a given string except first one code example
Example 1: how to remove duplicate elements from char array in java
public static void main(String[] args) {
Main main = new Main();
char[] array = {'e','a','b','a','c','d','b','d','c','e'};
main.getCharArray(array);
}
private char[] getCharArray(char[] array) {
String _array = "";
for(int i = 0; i < array.length; i++) {
if(_array.indexOf(array[i]) == -1)
_array = _array+array[i];
}
return _array.toCharArray();
}
Example 2: removing repeated characters in a string c++
s.erase(std::unique(s.begin(), s.end()), s.end());