I am trying to find number of unique characters in a String. Solution have to be as efficient (time complexity O(N); very big arrays; in general Big O) as possible. I have decided to do it this way (if you have any better solution please let me know). The only problem is that when I try to run it it always says there is only one distinct value. It seems there is a problem with the Collections.addAll
method (maybe am using it wrong). Please let me know how to fix it. It seems it is only taking first character in an array. Thank you.
String ds = "acvdgefav";
char[] sa = ds.toCharArray();
for (int i=0; i<sa.length; i++)
System.out.println(sa[i]);
System.out.println();
System.out.println(sa.length);
System.out.println();
HashSet hs = new HashSet();
Collections.addAll(hs, sa);
for (int i=0; i<hs.size(); i++)
System.out.println(sa[i]);
System.out.println();
int z = hs.size();
System.out.println(z);