Java Array Equal arraysEquals(byte[] a, byte[] b)

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

Description

arrays Equals

License

Open Source License

Declaration

public static boolean arraysEquals(byte[] a, byte[] b) 

Method Source Code

//package com.java2s;
/*//from w w w. j av a  2s . co m
TruPax  Copyright (C) 2015  CODERSLAGOON
    
TruPax is free software: you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
Foundation, either version 3 of the License, or (at your option) any later
version.
    
TruPax is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
TruPax. If not, see http://www.gnu.org/licenses/.
    
*/

public class Main {
    public static boolean arraysEquals(byte[] a, byte[] b) {
        if (a.length != b.length) {
            return false;
        }
        return arraysEquals(a, 0, b, 0, a.length);
    }

    public static boolean arraysEquals(byte[] a, int ofsA, byte[] b, int ofsB, int len) {
        int end = ofsA + len;
        while (ofsA < end) {
            if (b[ofsB++] != a[ofsA++]) {
                return false;
            }
        }
        return true;
    }

    public static boolean arraysEquals(char[] a, char[] b) {
        if (a.length != b.length) {
            return false;
        }
        return arraysEquals(a, 0, b, 0, a.length);
    }

    public static boolean arraysEquals(char[] a, int ofsA, char[] b, int ofsB, int len) {
        int end = ofsA + len;
        while (ofsA < end) {
            if (b[ofsB++] != a[ofsA++]) {
                return false;
            }
        }
        return true;
    }

    public static boolean arraysEquals(int[] a, int[] b) {
        if (a.length != b.length) {
            return false;
        }
        return arraysEquals(a, 0, b, 0, a.length);
    }

    public static boolean arraysEquals(int[] a, int ofsA, int[] b, int ofsB, int len) {
        int end = ofsA + len;
        while (ofsA < end) {
            if (b[ofsB++] != a[ofsA++]) {
                return false;
            }
        }
        return true;
    }
}

Related

  1. arraysEqual(byte[] bytes, byte[] ints)
  2. arraysEqual(final Object[] a1, final Object[] a2)
  3. arraysEqual(Object[] array1, Object[] array2)
  4. arraysEqual(String[] arr1, String[] arr2)
  5. arraysEqual(String[] one, String[] other)
  6. arraysEquals(byte[] a, int ofsA, byte[] b, int ofsB, int len)
  7. arraysEquals(byte[] arr1, int offset1, byte[] arr2, int offset2)
  8. arraysEquals(Object[] mThis, Object[] mThat)
  9. blobsAreEqual(byte[] blob1, byte[] blob2)