Java Utililty Methods Byte Array Compare

List of utility methods to do Byte Array Compare

Description

The list of methods to do Byte Array Compare are organized into topic(s).

Method

intmemcmp(byte[] bytes, byte[] bytes2, int nbElem)
Memory comparison
for (int i = 0; i < nbElem; i++) {
    Byte left = bytes[i];
    Byte right = bytes2[i];
    int compare = left.compareTo(right);
    if (compare != 0) {
        return compare;
return 0;
intmemcmp(byte[] s1, int s1Size, int s1offset, byte[] s2, int s2Size, int s2offset)
Equiv of C library memcmp().
int n = s1Size - s1offset;
if (n > (s2Size - s2offset)) {
    n = s2Size - s2offset;
for (int i = 0; i < n; i++) {
    if (s1[i + s1offset] != s2[i + s2offset]) {
        return s1[i + s1offset] < s2[i + s2offset] ? -1 : 1;
return 0;
intmemcmp(final byte[] a, final byte[] b, int length)
memcmp
for (int i = 0; i < length; i++) {
    if (a[i] != b[i]) {
        return (a[i] & 0xFF) - (b[i] & 0xFF);
return 0;
intmemcmp(final byte[] first, final int firstStart, final byte[] second, final int secondStart, int size)
memcmp
assert firstStart + size <= first.length;
assert secondStart + size <= second.length;
int cmp;
for (int i = 0; i < size; i++) {
    if ((cmp = (first[firstStart + i] & 0xff) - (second[secondStart + i] & 0xff)) != 0) {
        return cmp;
return 0;
intmemcmp(List header, String string, int size)
memcmp
for (int i = 0; i < size; i++) {
    if (header.get(i) != (byte) string.charAt(i))
        return 1;
return 0;