I was asked to write a program to print values in a character array. This array contains duplicated values, but output should not contain duplicated characters.Do not use Set. This is what I have created. Let me know if there is any other and efficient way to do the same.
public class RemoveDuplication {
public static void main (String[] args){
char[] a= new char[]{'a', 'b', 'c', 'a', 'b', 'c', 'a', 'b', 'c', 'a', 'b', 'c'};
String s=Character.toString(a[0]);
for (int i=1; i<a.length; i++) {
if ((s.indexOf(a[i])) == -1) {
s = s + Character.toString(a[i]);
} else {
}
}
// if you want character array as result
char[] result = s.toCharArray();
System.out.println(result);
}
}
System.out.println(Arrays.toString(result));