找到Java中N个字节数组列表的共同元素

huangapple go评论62阅读模式
英文:

Find common elements among N lists of byte arrays in Java

问题

我有一个声明,如List<List<byte[]>>,即内部列表是字节数组的列表,有N个这样的列表。我想找出所有列表中的共同字节数组。我应该如何做?这里有一个讨论,但我不知道它是否适用于字节数组。

英文:

I have a declaration as List&lt;List&lt;byte[]&gt;&gt;, 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.

huangapple
  • 本文由 发表于 2020年7月26日 14:39:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/63096939.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定