Java Array Index Of ArrayIndexOf(byte[] data, byte[] dest)

Here you can find the source of ArrayIndexOf(byte[] data, byte[] dest)

Description

Array Index Of

License

Apache License

Declaration

public static int ArrayIndexOf(byte[] data, byte[] dest) 

Method Source Code

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

public class Main {

    public static int ArrayIndexOf(byte[] data, byte[] dest) {
        return ArrayIndexOf(data, dest, 0);
    }/* ww  w  . ja  va 2  s  .c o m*/

    public static int ArrayIndexOf(byte[] data, byte[] dest, int start) {
        if (data == null || data.length == 0 || dest == null || dest.length == 0 || data.length < dest.length
                || start < 0) {
            return -1;
        }
        for (int i = start; i < data.length; i++) {
            boolean found = true;
            for (int j = 0; j < dest.length; j++) {
                if (data[i + j] != dest[j]) {
                    found = false;
                    break;
                }
            }
            if (found) {
                return i;
            }
        }
        return -1;
    }
}

Related

  1. arrayIndex(T[] arr, T item)
  2. arrayIndexCheck(char[] text, int startPos, int endPos)
  3. arrayIndexClean(String indx)
  4. arrayIndexFor(final String raw)
  5. arrayIndexOf(int needle, int[] haystack)
  6. arrayIndexOf(int value, int[] arr)
  7. arrayIndexOf(Object[] array, Object element)
  8. arrayIndexOffset(int index, long baseOffset, long indexScale)