Home > Back-end >  What does it mean if something is equal to -1?
What does it mean if something is equal to -1?

Time:11-22

Can anyone explain to me what it means?

Example:

for(char ch : (a b).toCharArray()){
  if(a.indexOf(ch) == -1 || b.indexOf(ch) == -1){
    ...
  }
}

I want to understand the meaning of -1.

CodePudding user response:

a.indexOf(ch) == -1: It means that the character ch is not found in string a Extended explanation: indexOf() : This method returns the index within this string of the first occurrence of the specified character or -1, if the character does not occur.

CodePudding user response:

-1 if it never occurs.

learn more about the method here - https://www.w3schools.com/java/ref_string_indexof.asp

  •  Tags:  
  • java
  • Related