Q:

Need an If Statement syntax explanation

Forgive my foolishness, but I want to know in the part of code below:
String titleTag = "<title>";
String endTitleTag = "</title>";
int titleStart = line.indexOf(titleTag);
int titleEnd = line.indexOf(endTitleTag);

if (titleStart != -1 && titleEnd != -1) 
{
String title = line.substring(titleStart + titleTag.length(),titleEnd);

if (checkTitleIfMatched(title)) {
System.out.println(String.format("%s - %s", title, location));

word.set(title);
context.write(word, location);
  }
}

What is the role of the -1, why we make this ,let's say,  comparison?
Thank you in advance

A:

The indexOf method returns the index of the searched string. If the string is not found, it returns -1. That's why you have that comparison, it's to make sure that the searched string is found.

