Java - Write code to get the index of an element in an array

Requirements

Write code to get the index of an element in an array

Demo

//package com.book2s;

public class Main {
    public static void main(String[] argv) {
        String el = "book2s.com";
        String[] ar = new String[] { "1", "abc", "level", null,
                "book2s.com", "asdf 123" };
        System.out.println(index(el, ar));
    }//from w  ww.  j a  v  a 2s. com

    /**
     * @return the index of the first element in "ar" that is equals to "el" or
     *         -1 (if there is no element equal to el).
     */
    public static int index(final String el, final String[] ar) {
        for (int i = 0; i < ar.length; ++i) {
            if (ar[i].equals(el))
                return i;
        }
        return -1;
    }
}