Java Array Contain arrayContains(byte[] a, int offset, byte[] b)

Here you can find the source of arrayContains(byte[] a, int offset, byte[] b)

Description

Returns true if an array's elements appear inside another array.

License

Open Source License

Parameter

Parameter Description
a haystack
offset starting index in haystack for the comparison
b needle

Return

true if every byte of needle matches haystack, beginning at start

Declaration

private static boolean arrayContains(byte[] a, int offset, byte[] b) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**/*from  w  w  w . jav a2 s  .  c om*/
     * Returns true if an array's elements appear inside another array.
     *
     * @param a  haystack
     * @param offset  starting index in haystack for the comparison
     * @param b  needle
     * @return true if every byte of needle matches haystack, beginning at start
     */
    private static boolean arrayContains(byte[] a, int offset, byte[] b) {
        if (a.length < offset + b.length)
            return false;

        for (int i = 0; i < b.length; i++) {
            if (a[offset + i] != b[i])
                return false;
        }
        return true;
    }
}

Related

  1. ARRAY_Contains(int value, int[] array)
  2. arrayContains(char[] chars, char cToFind)
  3. arrayContains(char[] chars, char cToFind)
  4. arrayContains(final byte[] what, final byte[] b)
  5. arrayContains(final E[] arr, final E targetValue)