Here you can find the source of fromListToSetByteArray(List
private static Set<byte[]> fromListToSetByteArray(List<ByteBuffer> list)
//package com.java2s; //License from project: Apache License import java.nio.ByteBuffer; import java.util.Comparator; import java.util.List; import java.util.Set; import java.util.TreeSet; public class Main { private static Set<byte[]> fromListToSetByteArray(List<ByteBuffer> list) { Set<byte[]> set = new TreeSet<byte[]>(new Comparator<byte[]>() { @Override/* w ww .j a v a2 s . c o m*/ public int compare(byte[] left, byte[] right) { return compareTo(left, 0, left.length, right, 0, right.length); } public int compareTo(byte[] buffer1, int offset1, int length1, byte[] buffer2, int offset2, int length2) { if (buffer1 == buffer2 && offset1 == offset2 && length1 == length2) { return 0; } //WritableComparator code int end1 = offset1 + length1; int end2 = offset2 + length2; for (int i = offset1, j = offset2; i < end1 && j < end2; i++, j++) { int a = (buffer1[i] & 0xff); int b = (buffer2[j] & 0xff); if (a != b) { return a - b; } } return length1 - length2; } }); for (ByteBuffer e : list) { set.add(e.array()); } return set; } }