public class RemoveDuplicatedChar { public static void removeDuplicated(char[] str) { if (str == null) return; int len = str.length; if (len < 2) return; int tail = 1; for (int i = 1; i < len; i++) { int j; for (j = 0; j < tail; j++) { if (str[i] == str[j]) break; } if (j == tail) { str[tail] = str[i]; tail++; } } while (tail < len) { str[tail++] = '\0'; } } public static void main(String[] args) { char[] str = { 'a', 'b', 'c', 'd', 'e', 'c', 'f', 'g', 'e', 'h' }; System.out.println(str); removeDuplicated(str); System.out.println(str); } }