title: What does the function fullName.indexOf(",") != -1 do?
body: <p>Im trying to solve a problem that asks for these perimeters: </p>
  
  <p>"<em>A String variable, fullName, contains a name in one of two formats:
  last name,  first name (comma followed by a blank), or
  first name  last name (single blank)
  Extract the first name into the String variable firstName and the last name into the String variable lastName. Assume the variables have been declared and fullName already initialized. You may also declare any other necessary variables.</em>"</p>
  
  <p>My question is why does the <code>fullName.indexOf(",") != -1</code> part work? What does it do? Can someone explain negative index to me? Because from what I see the index of a comma in the fullName would be a lot more than -1 since it is in the middle of the sentence</p>
  
  <p>This is the code I found to answer it:</p>
  
  <pre><code>if (fullName.indexOf(",") != -1){
  
      lastName = fullName.substring(0, fullName.indexOf(","));
      firstName = fullName.substring(fullName.indexOf(",") +2 , fullName.length());
  }
  
  else{
  
      firstName= fullName.substring(0, fullName.indexOf(" "));
      lastName= fullName.substring(fullName.indexOf(" ")+1, fullName.length());
  }
  </code></pre>