What's the easiest way in Java to compare the contents of two ByteBuffers to check for equality?
compareTo is meant for ordering, if you want to check for equality you should use equals().
Thomas Lötzer
2010-09-22 14:44:16
yup, even better.
Jason S
2010-09-22 15:11:46
+5
A:
You could check the equals()
method too.
Tells whether or not this buffer is equal to another object.
Two byte buffers are equal if, and only if,
- They have the same element type,
- They have the same number of remaining elements, and
- The two sequences of remaining elements, considered independently of their starting positions, are pointwise equal.
A byte buffer is not equal to any other type of object.
Colin Hebert
2010-09-22 13:53:13
With a reputation of 17.7 k we can probably assume he has considered the `.equals` method. I suspect the OP wants to compare content only.
aioobe
2010-09-22 14:39:43
Of course I'm human, I forgot to check the javadoc first before asking. Duh. :-) And I asked to check for equality, so this is the best method.
Jason S
2010-09-22 15:11:26