Search Substring in String
This program searches for substring in string.
Problem Statement
Write a Java program to check if "inq" exists in "EduinqString".
Source Code
| 1 | public class SubstringSearch { |
| 2 | public static void main(String[] args) { |
| 3 | System.out.println("Eduinq Substring Search"); |
| 4 | String str="EduinqString"; |
| 5 | if(str.contains("inq")) System.out.println("Substring found"); |
| 6 | else System.out.println("Substring not found"); |
| 7 | } |
| 8 | } |
Program Output
Eduinq Substring Search Substring found
Explanation
The contains() method checks whether a substring exists anywhere within the target string, returning true if it is present, demonstrating substring search.