You can avoid wrappers and a silly hash problem (hey, the standard thing, for example, byte [] does not have hashCode?):
Use TreeSet instead of HashSet and provide a byte [] comparator during instance creation:
Set<byte[]> byteATreeSet = new TreeSet<byte[]>(new Comparator<byte[]>() { public int compare(byte[] left, byte[] right) { for (int i = 0, j = 0; i < left.length && j < right.length; i++, j++) { int a = (left[i] & 0xff); int b = (right[j] & 0xff); if (a != b) { return a - b; } } return left.length - right.length; }});
If you get the HashSet b byte [] from another place, initialize your variable a before TreeSet, and then use a.addAll (b); Thus, even if b contains duplicates, a does not.
ib84
source share