英文:
Find common elements among N lists of byte arrays in Java
问题
我有一个声明,如List<List<byte[]>>
,即内部列表是字节数组的列表,有N个这样的列表。我想找出所有列表中的共同字节数组。我应该如何做?这里有一个讨论,但我不知道它是否适用于字节数组。
英文:
I have a declaration as List<List<byte[]>>
, i.e. inner list is list of byte arrays and there are N such lists. I want to identify common byte arrays across all the lists. How would I do that? There is a discussion here, but I donot know if it works for byte arrays
答案1
得分: 0
你可以使用equals(byte[] a, byte[] a2)
,如此处所建议。
英文:
You can use equals(byte[] a, byte[] a2)
, as suggested here.
答案2
得分: 0
使用你提供的解决方案,但是由于数组没有覆盖 hashCode
方法,你需要将它们包装在 ByteBuffer
中,使用 ByteBuffer.wrap
方法。要从 ByteBuffer
中提取数组,请在其上调用 array
方法。
英文:
Use the solution you've linked, but as arrays don't have hashCode
overriden, you have to wrap them in ByteBuffer
, using ByteBuffer.wrap
. To extract the array from a ByteBuffer
, call array
on it.
专注分享java语言的经验与见解,让所有开发者获益!
评论