How to split a byte[]
around a byte sequence in Java? Something like the byte[]
version of String#split(regex)
.
Example
Let's take this byte array:
[11 11 FF FF 22 22 22 FF FF 33 33 33 33]
and let's choose the delimiter to be
[FF FF]
Then the split will result in these three parts:
[11 11]
[22 22 22]
[33 33 33 33]
EDIT:
Please note that you cannot convert the byte[]
to String
, then split it, then back because of encoding issues. When you do such conversion on byte arrays, the resulting byte[]
will be different. Please refer to this:
Conversion of byte[] into a String and then back to a byte[]