title: How to use Wrap Method of ByteBuffer in Java
body: <p>Okay, so I was looking up what the best way to convert from a byte array to it's numeric value in java was and I came across this <a href="https://stackoverflow.com/questions/1026761/how-to-convert-a-byte-array-to-its-numeric-value-java">link</a>. And the second answer mentions the use of the ByteBuffer class. For those that do not wish to click on the link, originally the question asks if I have:</p>
  
  <pre><code>byte[] by = new byte[8];
  </code></pre>
  
  <p>How does one convert that to int? Well the answer goes...</p>
  
  <pre><code>ByteBuffer bb = ByteBuffer.wrap(new byte[] {0, 0, 0, 0, 0, 0, 0, 4});
  long l = bb.getLong();
  
  System.out.println(l);
  </code></pre>
  
  <p>Result</p>
  
  <pre><code>4
  </code></pre>
  
  <p>And that is awesome to learn, but I just want to confirm something before going that route.</p>
  
  <p>Say I have a previously read in byte array that is 8 bytes long.</p>
  
  <pre><code>byte[] oldByte = new byte[8];
  </code></pre>
  
  <p>then I do...</p>
  
  <pre><code>ByteBuffer bb = ByteBuffer.wrap(new byte[] {oldByte[2], oldByte[3]});
  int intValue = bb.getInt();
  </code></pre>
  
  <p>Will that work/be read in the same manner as the previous example?</p>