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.
31k questions
32.8k answers
501 comments
693 users