Java Byte Array Equal byteArrayEquals(byte[] b1, byte[] b2)

Here you can find the source of byteArrayEquals(byte[] b1, byte[] b2)

Description

byte Array Equals

License

Open Source License

Declaration

public static boolean byteArrayEquals(byte[] b1, byte[] b2) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2009 Zhao and others./* w w  w . j  a v  a  2  s.com*/
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Zhao - initial API and implementation
 *******************************************************************************/

public class Main {
    public static boolean byteArrayEquals(byte[] b1, byte[] b2) {
        if (b1 != null && b2 != null && b1.length == b2.length) {
            for (int i = 0; i < b1.length; i++) {
                if (b1[i] != b2[i])
                    return false;
            }
            return true;
        } else {
            return false;
        }

    }
}

Related

  1. byteArrayEquals(byte[] a1, byte[] a2)
  2. byteArrayEquals(final byte[] actual, final byte[] expected)
  3. byteArrayEquals(final byte[] lhs, final byte[] rhs)
  4. byteArraysEqual(byte[] b1, byte[] b2)
  5. bytesEqual(byte[] a, byte[] b)