Java Array Last Index Of lastIndexOf(Object[] array, Object object)

Here you can find the source of lastIndexOf(Object[] array, Object object)

Description

last Index Of

License

Open Source License

Declaration

public static int lastIndexOf(Object[] array, Object object) 

Method Source Code

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

public class Main {
    public static int lastIndexOf(Object[] array, Object object) {
        if (object != null) {
            for (int i = array.length - 1; i >= 0; i--) {
                if (object.equals(array[i])) {
                    return i;
                }/*www  . ja v a 2  s  . c o  m*/
            }

            return -1;
        }

        for (int i = array.length - 1; i >= 0; i--) {
            if (array[i] == null) {
                return i;
            }
        }

        return -1;
    }

    public static int lastIndexOf(byte[] array, byte value) {
        return lastIndexOf(toBoxedArray(array), value);
    }

    public static int lastIndexOf(char[] array, char value) {
        return lastIndexOf(toBoxedArray(array), value);
    }

    public static int lastIndexOf(double[] array, double value) {
        return lastIndexOf(toBoxedArray(array), value);
    }

    public static int lastIndexOf(float[] array, float value) {
        return lastIndexOf(toBoxedArray(array), value);
    }

    public static int lastIndexOf(int[] array, int value) {
        return lastIndexOf(toBoxedArray(array), value);
    }

    public static int lastIndexOf(long[] array, long value) {
        return lastIndexOf(toBoxedArray(array), value);
    }

    public static int lastIndexOf(short[] array, short value) {
        return lastIndexOf(toBoxedArray(array), value);
    }

    public static Boolean[] toBoxedArray(boolean[] array) {
        final Boolean[] objectArray = new Boolean[array.length];
        for (int i = 0; i < array.length; i++) {
            objectArray[i] = array[i];
        }
        return objectArray;
    }

    public static Byte[] toBoxedArray(byte[] array) {
        final Byte[] objectArray = new Byte[array.length];
        for (int i = 0; i < array.length; i++) {
            objectArray[i] = array[i];
        }
        return objectArray;
    }

    public static Character[] toBoxedArray(char[] array) {
        final Character[] objectArray = new Character[array.length];
        for (int i = 0; i < array.length; i++) {
            objectArray[i] = array[i];
        }
        return objectArray;
    }

    public static Double[] toBoxedArray(double[] array) {
        final Double[] objectArray = new Double[array.length];
        for (int i = 0; i < array.length; i++) {
            objectArray[i] = array[i];
        }
        return objectArray;
    }

    public static Float[] toBoxedArray(float[] array) {
        final Float[] objectArray = new Float[array.length];
        for (int i = 0; i < array.length; i++) {
            objectArray[i] = array[i];
        }
        return objectArray;
    }

    public static Integer[] toBoxedArray(int[] array) {
        final Integer[] objectArray = new Integer[array.length];
        for (int i = 0; i < array.length; i++) {
            objectArray[i] = array[i];
        }
        return objectArray;
    }

    public static Long[] toBoxedArray(long[] array) {
        final Long[] objectArray = new Long[array.length];
        for (int i = 0; i < array.length; i++) {
            objectArray[i] = array[i];
        }
        return objectArray;
    }

    public static Short[] toBoxedArray(short[] array) {
        final Short[] objectArray = new Short[array.length];
        for (int i = 0; i < array.length; i++) {
            objectArray[i] = array[i];
        }
        return objectArray;
    }
}

Related

  1. lastIndexOf(final char[] source, final int start, final int end, final char ch)
  2. lastIndexOf(final Object[] array, final Object objectToFind)
  3. lastIndexOf(int[] array, int intToFind)
  4. lastIndexOf(int[] array, int valueToFind)
  5. lastIndexOf(Object o, Object[] vals)
  6. lastIndexOf(Object[] array, Object objectToFind)
  7. lastIndexOf(Object[] elements, Object value)
  8. lastIndexOf(String source, char[] chars)
  9. lastIndexOf(String str, String[] path)