Java - Write code to get last Index Of Any element in an array

Requirements

Write code to get last Index Of Any element in an array

Demo

//package com.book2s;

public class Main {
    public static void main(String[] argv) {
        String str = "book2s.com";
        String[] searchStrs = new String[] { "1", "abc", "level", null,
                "book2s.com", "asdf 123" };
        System.out.println(lastIndexOfAny(str, searchStrs));
    }//  w ww .  j  a v  a2 s  . c o  m

    public static int lastIndexOfAny(String str, String[] searchStrs) {
        if ((str == null) || (searchStrs == null)) {
            return -1;
        }

        int searchStrsLength = searchStrs.length;
        int index = -1;
        int tmp = 0;

        for (int i = 0; i < searchStrsLength; i++) {
            String search = searchStrs[i];

            if (search == null) {
                continue;
            }

            tmp = str.lastIndexOf(search);

            if (tmp > index) {
                index = tmp;
            }
        }

        return index;
    }

}