Here you can find the source of arrayEquals(byte[] left, byte[] right)
Parameter | Description |
---|---|
left | a parameter |
right | a parameter |
public static boolean arrayEquals(byte[] left, byte[] right)
//package com.java2s; /*/*from w w w . j ava 2 s . c o m*/ * Part of the CCNx Java Library. * * Copyright (C) 2008-2012 Palo Alto Research Center, Inc. * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 2.1 * as published by the Free Software Foundation. * This library 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 * Lesser General Public License for more details. You should have received * a copy of the GNU Lesser General Public License along with this library; * if not, write to the Free Software Foundation, Inc., 51 Franklin Street, * Fifth Floor, Boston, MA 02110-1301 USA. */ public class Main { /** * byte array compare * @param left * @param right * @return true if equal */ public static boolean arrayEquals(byte[] left, byte[] right) { if (left == null) { return ((right == null) ? true : false); } if (right == null) { return ((left == null) ? true : false); } if (left.length != right.length) return false; for (int i = 0; i < left.length; i++) { if (left[i] != right[i]) return false; } return true; } /** * byte array compare * @param left * @param right * @param length * @return true if equal */ public static boolean arrayEquals(byte[] left, byte[] right, int length) { if (left == null) { return ((right == null) ? true : false); } if (right == null) { return ((left == null) ? true : false); } // If one of left or right is shorter than length, arrays // must be same length to be equal. if (left.length < length || right.length < length) if (left.length != right.length) return false; int minarray = (left.length < right.length) ? left.length : right.length; int minlen = (length < minarray) ? length : minarray; for (int i = 0; i < minlen; i++) { if (left[i] != right[i]) return false; } return true; } }