I use a byte array to fit 1024 bytes. The problem is, at separate times in my code I need to only use SOME of those bits. In C, I have used…
byte buff[] = read();
strcmp( buff, "CMD\r\n" );
This would ignore all later bytes in the array, and only compare the first 5 bytes. Is there an easy way to do this in Java?
You can compare an array of bytes with Arrays.equals( byte[], byte[] ).
EDIT: I missed that your byte array is 1024 bytes.
One option is to compare a slice of the byte array:
Another option is to convert the byte array up to a String, allowing an expression similar to C++.