Java Array Starts With startsWith(byte[] source, int offset, byte[] match)

Here you can find the source of startsWith(byte[] source, int offset, byte[] match)

Description

Does this byte array begin with match array content?

License

Apache License

Parameter

Parameter Description
source Byte array to examine
offset An offset into the <code>source</code> array
match Byte array to locate in <code>source</code>

Return

true If the starting bytes are equal

Declaration

public static boolean startsWith(byte[] source, int offset, byte[] match) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {

    public static boolean startsWith(byte[] source, byte[] match) {
        return startsWith(source, 0, match);
    }/*from w  ww  .j  a  va 2 s.c o  m*/

    /**
     * Does this byte array begin with match array content?
     *
     * @param source Byte array to examine
     * @param offset An offset into the <code>source</code> array
     * @param match  Byte array to locate in <code>source</code>
     * @return true If the starting bytes are equal
     */
    public static boolean startsWith(byte[] source, int offset, byte[] match) {

        if (match.length > (source.length - offset)) {
            return false;
        }

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

Related

  1. startsWith(byte[] nameRaw, byte[] namePrefix)
  2. startsWith(byte[] p, byte id)
  3. startsWith(byte[] prefix, byte[] source)
  4. startsWith(byte[] source, byte[] match)
  5. startsWith(byte[] source, byte[] match)
  6. startsWith(byte[] target, byte[] search, int offset)
  7. startsWith(byte[] target, int offset, byte[] litmusPaper)
  8. startsWith(char s[], int len, String prefix)
  9. startsWith(char[] prefix, char[] other)