Search code examples
javaarrayscollectionsguava

Find common elements among N lists of byte arrays in Java


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


Solution

  • 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.