Ask a Question
Ask Question Login
Corporate Training
  1. Community
  2. Java
  3. Question
Java

Can I execute a Java method for finding the substring of a string?

Asked by Celina Lagunas Jan 12, 2024 884 views 1 answer
Share

About this question

 I am currently working on an application that is related to the text process in which users can input their sentences, and the program needs to verify if a particular substring exists in those sentences of the users or not. For this specific purpose, I need to execute a Java method that can check the substrings. My code should look like this:-

Public class SubstringChecker {
    Public static boolean containsSubstring(String mainString, String subString) {
        // Your implementation here
        
    }
    Public static void main(String[] args) {
        String text = “This is a sample text to check if substring exists.”;
        String wordToCheck = “sample”;
        Boolean isSubstring = containsSubstring(text, wordToCheck);
        System.out.println(“Does the text contain the word ‘sample’? “ + isSubstring);
    }
}

Your answer

1 Answer

More Java discussions

Learn & Explore

Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.

Latest Java Blogs

Guides, tips and career advice on Java from JanBask experts.