Here you can find the source of arrayEqualsSubset(final byte[] array, final int... elements)
Parameter | Description |
---|---|
array | the byte array |
elements | the byte elements to compare |
public static boolean arrayEqualsSubset(final byte[] array, final int... elements)
//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; } }