Issue
In Java is there a way to check the condition:
"Does this single character appear at all in string x"
without using a loop?
Solution
You can use href="http://docs.oracle.com/javase/7/docs/api/java/lang/String.html#indexOf%28int%29" rel="noreferrer">string.indexOf('a')
.
If the char a
is present in string
:
it returns the the index of the first occurrence of the character in the character sequence represented by this object, or -1 if the character does not occur.
Answered By - mP.
Answer Checked By - Mary Flores (JavaFixing Volunteer)