Here you can find the source of compareNotNull(byte[] data1, byte[] data2)
Parameter | Description |
---|---|
data1 | the first byte array (must not be null) |
data2 | the second byte array (must not be null) |
public static int compareNotNull(byte[] data1, byte[] data2)
//package com.java2s; /*//from w w w. j a va 2 s .c o m * Copyright 2004-2008 H2 Group. Multiple-Licensed under the H2 License, Version 1.0, and under the Eclipse Public License, Version 1.0 (http://h2database.com/html/license.html). Initial Developer: H2 Group */ public class Main { /** * Compare the contents of two byte arrays. If the content or length of the first array is smaller than the second array, -1 is returned. If the content or length of the second array is smaller than the first array, 1 is returned. If the contents and lengths are the same, 0 is returned. * * @param data1 * the first byte array (must not be null) * @param data2 * the second byte array (must not be null) * @return the result of the comparison (-1, 1 or 0) */ public static int compareNotNull(byte[] data1, byte[] data2) { int len = Math.min(data1.length, data2.length); for (int i = 0; i < len; i++) { byte b = data1[i]; byte b2 = data2[i]; if (b != b2) { return b > b2 ? 1 : -1; } } int c = data1.length - data2.length; return c == 0 ? 0 : (c < 0 ? -1 : 1); } }