Hi@akhtar,
The first and foremost way to check for the presence of a substring is the .contains() method. It's provided by the String class itself and is very efficient. The method accepts a CharSequence and returns true if the sequence is present in the String we call the method on.
String string = "Java";
String substring = "va";
System.out.println(string.contains(substring));
Hope this helps!
Join Java Certification Program today and become certified expert.
Thanks!