Android Byte Array Search search(byte[] needle, byte[] haystack, int from, int to)

Here you can find the source of search(byte[] needle, byte[] haystack, int from, int to)

Description

search

License

Open Source License

Declaration

public static int search(byte[] needle, byte[] haystack, int from,
            int to) 

Method Source Code

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

public class Main {
    public static int search(byte[] needle, byte[] haystack, int from,
            int to) {
        for (int i = from; i < to - needle.length; i++) {
            boolean ok = true;
            for (int j = 0; j < needle.length; j++) {
                if (needle[j] != haystack[i + j]) {
                    ok = false;/*from   w  ww  . j  a  va  2s. c o m*/
                    break;
                }
            }
            if (ok) {
                return i;
            }
        }
        return -1;
    }
}

Related

  1. search(byte[] array, int start, int count, byte value)
  2. search(byte[] array, int start, int count, short value)