Java Array Last Index Of lastIndexOf(byte[] bytes, int pos, int len, byte b)

Here you can find the source of lastIndexOf(byte[] bytes, int pos, int len, byte b)

Description

Returns the index of the last occurrence of the specified byte in the specified array.

License

Open Source License

Parameter

Parameter Description
bytes the array of bytes
pos the starting position within the array
len the number of bytes to search
b the byte the byte to find

Return

the index of the last occurrence of the specified byte; returns -1 if the object is not found.

Declaration

public static int lastIndexOf(byte[] bytes, int pos, int len, byte b) 

Method Source Code

//package com.java2s;
/*/*from  www . ja  v  a2s  .  c  o  m*/
 * Copyright SparseWare Inc. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

public class Main {
    /**
     * Returns the index of the last occurrence of the specified byte in the specified
     * array.
     *
     * @param bytes  the array of bytes
     * @param pos    the starting position within the array
     * @param len    the number of bytes to search
     * @param b      the byte the byte to find
     *
     * @return   the index of the last occurrence of the specified byte; returns -1 if the
     *           object is not found.
     */
    public static int lastIndexOf(byte[] bytes, int pos, int len, byte b) {
        for (int i = len - 1; i >= pos; i--) {
            if (bytes[i] == b) {
                return i;
            }
        }

        return -1;
    }
}

Related

  1. arrayLastIndexOf(Object[] array, Object objectToFind)
  2. lastIndexOf(boolean[] array, boolean valueToFind)
  3. lastIndexOf(byte value, byte[] array)
  4. lastIndexOf(byte[] array, byte valueToFind)
  5. lastIndexOf(byte[] ary, byte value)
  6. lastIndexOf(byte[] data, int offset, int length, byte val)
  7. lastIndexOf(byte[] pattern, byte[] block)
  8. lastIndexOf(byte[] s, char c)
  9. lastIndexOf(byte[] source, byte[] match)