Java Byte Array Compare bytesCompare(byte[] a, byte[] b)

Here you can find the source of bytesCompare(byte[] a, byte[] b)

Description

bytes Compare

License

Apache License

Declaration

private static int bytesCompare(byte[] a, byte[] b) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    private static int bytesCompare(byte[] a, byte[] b) {
        if (null == a && null == b)
            return 0;
        if (null == a && null != b)
            return -1;
        if (null != a && null == b)
            return 1;

        int minLen = Math.min(a.length, b.length);
        for (int i = 0; i < minLen; ++i) {
            int v = (a[i] & 0xff) - (b[i] & 0xff);
            if (v != 0)
                return v;
        }// w  w  w.j  a va  2 s  . co  m

        if (a.length < b.length)
            return -1;
        else if (a.length > b.length)
            return 1;
        else
            return 0;
    }
}

Related

  1. allEquals(byte[] array, byte value, int offset, int maxLength)
  2. ArrayByteCompare(byte[] a, byte[] b)
  3. bytesCmp(byte[] oi, byte[] oj)
  4. bytesCompare(byte[] a, byte[] b)
  5. bytesCompare(byte[] bytes1, byte[] bytes2)
  6. memcmp(byte a[], int a_off, byte b[], int b_off, int len)
  7. memcmp(byte[] a, byte[] b)