Here you can find the source of compare(byte[] a, byte[] b)
Parameter | Description |
---|---|
a | a parameter |
b | a parameter |
public static boolean compare(byte[] a, byte[] b)
//package com.java2s; public class Main { /**/*from w w w . j av a2s .c o m*/ * Compare tow bytearrays. * * @param a * @param b * @return true if contents of two byte array are match. */ public static boolean compare(byte[] a, byte[] b) { if (a == null || b == null) { return a == b; } if (a.length != b.length) { return false; } for (int i = 0; i < a.length; i++) { if (a[i] != b[i]) { return false; } } return true; } /** * Compare parts of bytearrays. * * @param a * @param a_pos * @param b * @param b_pos * @param length * @return true if match. */ public static boolean compare(byte[] a, int a_pos, byte[] b, int b_pos, int length) { if (a == null || b == null) { return length == 0; } if ((a.length < a_pos + length) || (b.length < b_pos + length)) { return false; } for (int i = 0; i < length; i++) { if (a[a_pos + i] != b[b_pos + i]) { return false; } } return true; } }