-1

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,576
  • 13
  • 42
  • 57
scibor
  • 935
  • 4
  • 10
  • 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
  • 63,838
  • 26
  • 184
  • 242
2
for (String title : array) {
    if (title.toLowerCase().indexOf("math") != -1). {
        return true;
    } 
}
return false;
isaach1000
  • 1,789
  • 1
  • 12
  • 18