Android Byte Array Compare compareTo(byte[] buffer1, int offset1, int length1, byte[] buffer2, int offset2, int length2)

Here you can find the source of compareTo(byte[] buffer1, int offset1, int length1, byte[] buffer2, int offset2, int length2)

Description

compare To

Declaration

public static int compareTo(byte[] buffer1, int offset1, int length1,
            byte[] buffer2, int offset2, int length2) 

Method Source Code

//package com.java2s;

public class Main {
    public static int compareTo(final byte[] left, final byte[] right) {
        return compareTo(left, 0, left.length, right, 0, right.length);
    }/*from  w w  w.  j a  va2 s  . co  m*/

    public static int compareTo(byte[] buffer1, int offset1, int length1,
            byte[] buffer2, int offset2, int length2) {
        // Bring WritableComparator code local
        int end1 = offset1 + length1;
        int end2 = offset2 + length2;
        for (int i = offset1, j = offset2; i < end1 && j < end2; i++, j++) {
            int a = (buffer1[i] & 0xff);
            int b = (buffer2[j] & 0xff);
            if (a != b) {
                return a - b;
            }
        }
        return length1 - length2;
    }
}

Related

  1. compareByteArray(byte[] src, byte[] dst)
  2. compareByteArray(byte[] src, int srcOffset, byte[] dst, int dstOffset, int length)
  3. compareByteArray(byte[] src, int srcOffset, int srcLen, byte[] dst, int dstOffset, int dstLen)
  4. compareNotNull(byte[] data1, byte[] data2)
  5. compareSecure(byte[] test, byte[] good)
  6. compareTo(final byte[] left, final byte[] right)
  7. areEqual(byte[] a, byte[] b)
  8. compare(byte[] arr1, byte[] arr2)
  9. areByteArraysEqual(byte[] byteArray0, byte[] byteArray1)