This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
In the present case, indexOf() method is used.
The problem is that if my variable contains a value like SD06 & SD06(A) e.g. cdSD06xxSD06(A), and if I keep a while loop condition with method,
then, the code in the loop will be executed twice as it contains SD06 twice though I want to execute it just once as SD06 & SD06(A) are completely different from each other.
Answer the following question with one of: true or false.
I only want to find the first occurrence of the substring.
If you answered true, then there is no need for any sort of loop. And, by the way, an if statement is not considered a "loop". If the intent is to conditionally execute code if the substring is found, then yes, an if statement is appropriate.