0

I want to be able to check if the string input matches any of the strings in array, and then run only if it matches any of the strings.

String[] list = {"hey","hello"};

if (input == anyofthestringsinarray) {

}

Thought something like if(input.equalsIgnoreCase(list)) {} could work, but dont. Any tips?

Reporter
  • 3,897
  • 5
  • 33
  • 47

1 Answers1

2

Try this:

public static void stringContainsItemFromList(String inputStr, String[] items)
{
    for(int i =0; i < items.length; i++)
    {
        if(inputStr.contains(items[i]))
        {
           // if present do something
        }
    }
}
joy08
  • 9,004
  • 8
  • 38
  • 73