Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
3 views
in Java by (10.2k points)

In Java is there a way to check the condition:

"Does this single character appear at all in string x"

without using a loop?

1 Answer

0 votes
by (46k points)

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.

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
2 answers
asked Jul 9, 2019 in Java by Anvi (10.2k points)

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...