BAEL-4718 using bytes array as key in HashMap (#10315)
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user