Java Array Last Index Of lastIndexOf(char[] toBeFound, char[] array)

Here you can find the source of lastIndexOf(char[] toBeFound, char[] array)

Description

last Index Of

License

Open Source License

Declaration

public static final int lastIndexOf(char[] toBeFound, char[] array) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2004, 2005 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors://w  ww. j a  v a 2  s . c  o m
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/

public class Main {
    public static final int lastIndexOf(char[] toBeFound, char[] array) {
        int j = toBeFound.length - 1;
        for (int i = array.length; --i >= 0;) {
            if (toBeFound[j] == array[i]) {
                if (--j == -1)
                    return i;
            } else
                j = toBeFound.length - 1;
        }
        return -1;
    }
}

Related

  1. lastIndexOf(byte[] data, int offset, int length, byte val)
  2. lastIndexOf(byte[] pattern, byte[] block)
  3. lastIndexOf(byte[] s, char c)
  4. lastIndexOf(byte[] source, byte[] match)
  5. lastIndexOf(char[] toBeFound, char[] array)
  6. lastIndexOf(final byte[] reference, final byte[] query)
  7. lastIndexOf(final byte[] str, int startIndex, int endIndex, final byte ch)
  8. lastIndexOf(final char[] source, final int start, final int end, final char ch)
  9. lastIndexOf(final Object[] array, final Object objectToFind)