title: How to split a byte array around a byte sequence in Java?
body: <p>How to split a <code>byte[]</code> around a byte sequence in Java? Something like the <code>byte[]</code> version of <a href="http://docs.oracle.com/javase/6/docs/api/java/lang/String.html#split%28java.lang.String%29" rel="noreferrer"><code>String#split(regex)</code></a>.</p>
  <h3>Example</h3>
  <p>Let's take this byte array:<br />
  <code>[11 11 FF FF 22 22 22 FF FF 33 33 33 33]</code></p>
  <p>and let's choose the delimiter to be<br />
  <code>[FF FF]</code></p>
  <p>Then the split will result in these three parts:<br />
  <code>[11 11]</code><br />
  <code>[22 22 22]</code><br />
  <code>[33 33 33 33]</code></p>
  <h2>EDIT:</h2>
  <p>Please note that you cannot convert the <code>byte[]</code> to <code>String</code>, then split it, then back because of encoding issues. When you do such conversion on byte arrays, the resulting <code>byte[]</code> will be different. Please refer to this:
  <a href="https://stackoverflow.com/questions/2758654/conversion-of-byte-into-a-string-and-then-back-to-a-byte">Conversion of byte[] into a String and then back to a byte[]</a></p>