Here you can find the source of bytesEqual(byte[] a1, byte[] a2)
Parameter | Description |
---|---|
a1 | Array 1 |
a2 | Array 2 |
public static boolean bytesEqual(byte[] a1, byte[] a2)
//package com.java2s; /*// w w w .j av a 2 s . c o m * Copyright 2008-2013 LinkedIn, Inc * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. */ public class Main { /** * Test two byte arrays for (deep) equality. I think this exists in java 6 * but not java 5 * * @param a1 Array 1 * @param a2 Array 2 * @return True iff a1.length == a2.length and a1[i] == a2[i] for 0 <= i < * a1.length */ public static boolean bytesEqual(byte[] a1, byte[] a2) { if (a1 == a2) { return true; } else if (a1 == null || a2 == null) { return false; } else if (a1.length != a2.length) { return false; } else { for (int i = 0; i < a1.length; i++) if (a1[i] != a2[i]) return false; } return true; } }