Java Array Equal arraysEquals(byte[] arr1, int offset1, byte[] arr2, int offset2)

Here you can find the source of arraysEquals(byte[] arr1, int offset1, byte[] arr2, int offset2)

Description

arrays Equals

License

GNU General Public License

Declaration

public static boolean arraysEquals(byte[] arr1, int offset1, byte[] arr2, int offset2) 

Method Source Code

//package com.java2s;
/*/*from   w w  w . j a v  a2 s  .c  om*/
 * This is the source code of Telegram for Android v. 2.x.x.
 * It is licensed under GNU GPL v. 2 or later.
 * You should have received a copy of the license in this archive (see LICENSE).
 *
 * Copyright Nikolai Kudashov, 2013-2015.
 */

public class Main {
    public static boolean arraysEquals(byte[] arr1, int offset1, byte[] arr2, int offset2) {
        if (arr1 == null || arr2 == null || offset1 < 0 || offset2 < 0
                || arr1.length - offset1 != arr2.length - offset2 || arr1.length - offset1 < 0
                || arr2.length - offset2 < 0) {
            return false;
        }
        boolean result = true;
        for (int a = offset1; a < arr1.length; a++) {
            if (arr1[a + offset1] != arr2[a + offset2]) {
                result = false;
            }
        }
        return result;
    }
}

Related

  1. arraysEqual(Object[] array1, Object[] array2)
  2. arraysEqual(String[] arr1, String[] arr2)
  3. arraysEqual(String[] one, String[] other)
  4. arraysEquals(byte[] a, byte[] b)
  5. arraysEquals(byte[] a, int ofsA, byte[] b, int ofsB, int len)
  6. arraysEquals(Object[] mThis, Object[] mThat)
  7. blobsAreEqual(byte[] blob1, byte[] blob2)
  8. bytesAreEqual(byte[] b1, byte[] b2)
  9. equal(boolean[][] a, boolean[][] b)