mar*_*ssi 14 java sorting collections compare map
我有一个带有byte []键的hashmap.我想通过TreeMap对其进行排序.
为字典顺序执行比较器的最有效方法是什么?
mar*_*ssi 17
在Apache Hbase中找到了这段很好的代码:
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;
}
Run Code Online (Sandbox Code Playgroud)