Java Byte Array Compare bytesCompare(byte[] bytes1, byte[] bytes2)

Here you can find the source of bytesCompare(byte[] bytes1, byte[] bytes2)

Description

bytes Compare

License

Apache License

Declaration

public static int bytesCompare(byte[] bytes1, byte[] bytes2) 

Method Source Code

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

public class Main {
    public static int bytesCompare(byte[] bytes1, byte[] bytes2) {
        if (bytes1 == bytes2) {
            return 0;
        }//from ww  w.  ja va  2 s  .co  m
        int len1 = bytes1.length;
        int len2 = bytes2.length;
        int len = len1 < len2 ? len1 : len2;
        for (int i = 0; i < len; i++) {
            int a = (bytes1[i] & 0xff);
            int b = (bytes2[i] & 0xff);
            if (a != b) {
                return a - b;
            }
        }
        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[] a, byte[] b)
  6. memcmp(byte a[], int a_off, byte b[], int b_off, int len)
  7. memcmp(byte[] a, byte[] b)
  8. memcmp(byte[] a, int a_offset, byte[] b, int b_offset, int length)
  9. memcmp(byte[] a, int aoff, int alen, byte[] b, int boff, int blen)