Android Array Search indexof(byte[] shortBytes, byte[] longBytes)

Here you can find the source of indexof(byte[] shortBytes, byte[] longBytes)

Description

indexof

Declaration

public static int indexof(byte[] shortBytes, byte[] longBytes) 

Method Source Code

//package com.java2s;

public class Main {
    public static int indexof(byte[] shortBytes, byte[] longBytes) {
        for (int i = 0; i < longBytes.length; i++) {
            if (longBytes[i] == shortBytes[0]
                    && longBytes.length - i >= shortBytes.length) {
                boolean isIndexof = true;
                for (int j = 1; j < shortBytes.length; j++) {
                    if (shortBytes[j] != longBytes[i + j]) {
                        isIndexof = false;
                        continue;
                    }//from  w  ww . ja v a 2s.co m
                }
                if (isIndexof) {
                    return i;
                }
            }
        }
        return -1;
    }
}

Related

  1. inArray(Object o, Object... arr)
  2. indexOf(byte[] bytes, byte[] pattern, int start)
  3. indexOf(byte[] data, byte search)