Java - Write code to check if a string is In a String array

Requirements

Write code to check if a string is In a String array

Demo

//package com.book2s;

public class Main {
    public static void main(String[] argv) {
        String substring = "book2s.com";
        String[] source = new String[] { "1", "abc", "level", null,
                "book2s.com", "asdf 123" };
        System.out.println(isIn(substring, source));
    }//from  w  w w  .  jav  a  2s .  c  om

    public static boolean isIn(String substring, String[] source) {
        if (source == null || source.length == 0) {
            return false;
        }
        for (int i = 0; i < source.length; i++) {
            String aSource = source[i];
            if (aSource.equals(substring)) {
                return true;
            }
        }
        return false;
    }
}

Related Exercise