Back
In Java is there a way to check the condition:
"Does this single character appear at all in string x"
without using a loop?
You can use string.indexOf('a').
If the 'a' is present in string, it returns the index(>=0). If not, it returns -1. So, a non-negative return value means that 'a' is present in the string.
30.9k questions
32.9k answers
500 comments
665 users