BAEL-4718 using bytes array as key in HashMap (#10315)

This commit is contained in:
mdabrowski-eu
2020-12-18 06:13:31 +01:00
committed by GitHub
parent efc1277b0a
commit 83e87aebc0
2 changed files with 132 additions and 0 deletions
@@ -0,0 +1,28 @@
package com.baeldung.map.bytearrays;
import java.util.Arrays;
public final class BytesKey {
private final byte[] array;
public BytesKey(byte[] array) {
this.array = array;
}
public byte[] getArray() {
return array.clone();
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
BytesKey bytesKey = (BytesKey) o;
return Arrays.equals(array, bytesKey.array);
}
@Override
public int hashCode() {
return Arrays.hashCode(array);
}
}