-2

For instance, let's say I have the following array of app names:

{"Math Workshop", "Math Place", "Mathematics", "Angry Birds"}

I want to scan this array for any elements that contains the word math. How can I do that?

wattostudios
  • 8,666
  • 13
  • 43
  • 57
scibor
  • 983
  • 4
  • 12
  • 21

2 Answers2

4

Try the following code:

String[] appNames = {"Math Workshop", "Math Place", "Mathematics", 
    "Angry Birds"};

for (String name: appNames) {
  if (name.toLowerCase().contains("math")) {
    // TADA!!!
  }
}

Since contains() is case-sensitive, you will need to convert your string to lower case if you want a case-insensitive match.

Duncan Jones
  • 67,400
  • 29
  • 193
  • 254
2
for (String title : array) {
    if (title.toLowerCase().indexOf("math") != -1). {
        return true;
    } 
}
return false;
isaach1000
  • 1,819
  • 1
  • 13
  • 18