Java Array Index Of indexOf(byte[] target, byte[] key)

Here you can find the source of indexOf(byte[] target, byte[] key)

Description

index Of

License

Open Source License

Declaration

public static int indexOf(byte[] target, byte[] key) 

Method Source Code


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

import java.util.Arrays;

public class Main {
    public static int indexOf(byte[] target, byte[] key) {
        return indexOf(target, key, 0);
    }/*from  www.  java  2  s. com*/

    public static int indexOf(byte[] target, byte[] key, int from) {
        int result = -1;
        for (int i = from; i + key.length < target.length; i++) {
            if (Arrays.equals(Arrays.copyOfRange(target, i, i + key.length), key)) {
                result = i;
                break;
            }
        }
        return result;
    }

    public static int indexOf(byte[] target, byte key) {
        return indexOf(target, new byte[] { key });
    }

    public static int indexOf(byte[] target, byte key, int from) {
        return indexOf(target, new byte[] { key }, from);
    }
}

Related

  1. arrayIndexOf(int value, int[] arr)
  2. arrayIndexOf(Object[] array, Object element)
  3. arrayIndexOffset(int index, long baseOffset, long indexScale)
  4. indexOf(byte[] array, byte[] target, int fromIndex)
  5. indexOf(byte[] array, byte[] target, int start)
  6. indexOf(char toBeFound, char[] array)
  7. indexOf(final String[] p_elements, final String p_key)
  8. indexOf(final T[] array, final T value)
  9. indexOf(int[] arr, int e)