Java - Write code to Given a string, trim it, and if different from the string "", check to see if it is in a collection of strings (using equals()).

Requirements

Write code to Given a string, trim it, and if different from the string "", check to see if it is in a collection of strings (using equals()).

Demo

//package com.book2s;

public class Main {
    public static void main(String[] argv) {
        String searchString = "book2s.com";
        String searchStringList = "b";
        System.out.println(inAndNonEmpty(searchString, searchStringList));
    }/* w ww.  j a v  a2 s . c  om*/

    public static boolean inAndNonEmpty(final String searchString,
            final String... searchStringList) {
        if (searchString == null) {
            return false;
        }
        if (searchStringList.length == 0) {
            throw new IllegalArgumentException(
                    "argument SearchStringList must have length > 0");
        }
        final String trimmedString = searchString.trim();
        if (trimmedString.equals("")) {
            return false;
        }

        for (final String s : searchStringList) {
            if (s.equals(trimmedString)) {
                return true;
            }
        }
        return false;
    }
}