I am looking for a map implementation which uses byte arrays (byte[]) as the map key.
You can perform get operations like that map.get(myByteArray, 0, len);
Google did not help. 🙁
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can use ByteBuffer . It implements hashcode method in way that generated hash will depend upon the content of ByteBuffer. However you have to make sure that content of these buffer used as key should not change.
Direct from JavaDoc
Because buffer hash codes are content-dependent, it is inadvisable to use buffers as keys in hash maps or similar data structures unless it is known that their contents will not change.
This is one way to do this. Other is to implement your own class which will store byte array and implement hashCode() and equals() method which considers content of this byte array.