[英]how to do Collections.binarySearch on a collection of byte arrays?
This does not work: 这不起作用:
List<byte[]> byteArrayList = .... ;
Collections.binarySearch(byteArrayList, new ByteArrayComparator());
because byte[] does not extend Comparable. 因为byte []不扩展Comparable。 Why isn't it enough that a Comparator is provided? 为什么提供比较器还不够? Any tricks? 有什么花招吗?
Ups, error, i was sure I had the search term inside... Ups,错误,我确定我里面有搜索词...
As it stands, you're searching the list of byte arrays for a comparator. 就目前而言,您正在搜索字节数组列表中的比较器。 It looks like you're calling the wrong binarySearch method, ie this instead of this . 看来您在调用错误的binarySearch方法,即this而不是this 。
Try this: 尝试这个:
List<byte[]> byteArrayList = .... ;
byte[] valueToFind = .... ;
int index = Collections.binarySearch(byteArrayList,
valueToFind,
new ByteArrayComparator());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.