Java Array Last Index Of lastIndexOf(int[] array, int valueToFind)

Here you can find the source of lastIndexOf(int[] array, int valueToFind)

Description

last Index Of

License

Open Source License

Declaration

public static int lastIndexOf(int[] array, int valueToFind) 

Method Source Code

//package com.java2s;
/*//from  w w  w .j  ava 2s.  c om
 * #%L
 * G
 * %%
 * Copyright (C) 2014 Giovanni Stilo
 * %%
 * G is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this program.  If not, see
 * <https://www.gnu.org/licenses/lgpl-3.0.txt>.
 * #L%
 */

public class Main {
    public static int INDEX_NOT_FOUND = -1;

    public static int lastIndexOf(int[] array, int valueToFind) {
        int startIndex = array.length - 1;

        for (int i = startIndex; i >= 0; i--) {
            if (valueToFind == array[i]) {
                return i;
            }
        }
        return INDEX_NOT_FOUND;
    }
}

Related

  1. lastIndexOf(final byte[] reference, final byte[] query)
  2. lastIndexOf(final byte[] str, int startIndex, int endIndex, final byte ch)
  3. lastIndexOf(final char[] source, final int start, final int end, final char ch)
  4. lastIndexOf(final Object[] array, final Object objectToFind)
  5. lastIndexOf(int[] array, int intToFind)
  6. lastIndexOf(Object o, Object[] vals)
  7. lastIndexOf(Object[] array, Object object)
  8. lastIndexOf(Object[] array, Object objectToFind)
  9. lastIndexOf(Object[] elements, Object value)