title: Comparing bytes in a ByteBuffer
body: <p>I have a <code>byte</code> array in Java of size 4, which I am trying to put the first two bytes of into  <code>ByteBuffer</code>.</p>
  
  <p>Here is how I am doing it:</p>
  
  <pre><code>byte[] array = new byte[4];
  ByteBuffer buff = ByteBuffer.allocate(2);
  buff.put(array, 0, 2);
  </code></pre>
  
  <p>What's wrong with my code?</p>
  
  <p>EDIT:</p>
  
  <pre><code>byte[] currRecord = new byte[4];
  byte[] leftRecord = new byte[4];
  // Code that populates the records
  ByteBuffer currKey = ByteBuffer.allocate(2);
  currKey = currKey.put(currRecord, 0, 2);
  ByteBuffer leftKey = ByteBuffer.allocate(2);
  leftKey = leftKey.put(leftRecord, 0, 2);
  </code></pre>
  
  <p>Then I am trying to compare both <code>ByteBuffers</code> as follows:</p>
  
  <pre><code>if (currKey.compareTo(leftKey) &gt;= 0)
      return;
  </code></pre>
  
  <p>My comparison is always wrong. When debugging, I am pretty sure <code>currRecord</code> and <code>leftRecord</code> have the right values. The <code>ByteBuffer</code>s also have the right values (according to the debugger). What is the problem here?</p>