Java Array Equal arrayEqualsSubset(final byte[] array, final int... elements)

Here you can find the source of arrayEqualsSubset(final byte[] array, final int... elements)

Description

Checks that the byte array given matches the series of elements given as the varargs parameters.

License

Apache License

Parameter

Parameter Description
array the byte array
elements the byte elements to compare

Return

true if the subsets are equal

Declaration

public static boolean arrayEqualsSubset(final byte[] array, final int... elements) 

Method Source Code

//package com.java2s;
/*// w ww  .j  a v a 2 s. c  om
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You 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 {
    /**
     * Checks that the byte array given matches the series of elements given as the varargs
     * parameters. This returns false only if any elements are different, it does not check the
     * length of the byte array.
     *
     * @param array the byte array
     * @param elements the byte elements to compare
     * @return true if the subsets are equal
     */
    public static boolean arrayEqualsSubset(final byte[] array, final int... elements) {
        try {
            for (int i = 0; i < elements.length; i++)
                if (array[i] != (byte) elements[i])
                    return false;
        } catch (final ArrayIndexOutOfBoundsException e) {
            return false;
        }
        return true;
    }
}

Related

  1. arrayEquals(Object[] source, Object target)
  2. arrayEquals(Object[] source, Object target)
  3. arrayEquals(String[] array1, String[] array2)
  4. arrayEquals(String[] targetMethodParamTypes, String[] paramTypes)
  5. arrayEqualsExceptNull(Object[] a1, Object[] a2)
  6. arraysAreEqual(double[] a1, double[] a2)
  7. arraysAreEqual(final byte[] array1, final byte[] array2)
  8. arraysAreEqual(Object value, Object otherValue)
  9. arraysEqual(boolean[] a, boolean[] b)